This blog is under construction

Sunday 23 June 2013

C program to check whether the given values are in sequence or out of sequence

Write a C program to check whether the given values are in sequence or out of sequence.


  #include <stdio.h>
  #include <stdlib.h>
  int main() {
        int n, *entry, i, j, k, temp;

        /* get the number of entries from user */
        printf("Enter ur no of entries:");
        scanf("%d", &n);
        entry = (int *)malloc(sizeof (int) * n);

        /* get the entries from user */
        printf("Enter ur inputs:\n");
        for (i = 0; i < n; i++)
                scanf("%d", &entry[i]);

        /* check for insequence or out of sequence */
        for (i = 0;  i < n - 1; i++) {
                temp = entry[i];
                for (k = i - 1; k >= 0; k--) {
                        if (temp < entry[k]) {
                                printf("values are in out of sequence\n");
                                return 0;
                        }
                }
                for (j = i + 1; k < n; k++) {
                        if (temp > entry[j]) {
                                printf("Values are in out of sequence\n");
                                return 0;
                        }
                }
        }
        printf("Values are in sequence\n");
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter ur no of entries:5
  Enter ur inputs:
  100 200 150 300 450
  Values are in out of sequence



No comments:

Post a Comment