Ghislain_Mike

Practical

Mar 8th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int is123Array(int array[], int size) {
  5.     int mismatch = 0, result = 0, value, i;
  6.  
  7.     for (i = 0, value = 1; i < size, value <= 3; i++, value++) {
  8.         if (array[i] != value) {
  9.             mismatch++;
  10.         }
  11.     }
  12.  
  13.     if (mismatch > 0) {
  14.         result = 0;
  15.     } else {
  16.         result = 1;
  17.     }
  18.     return 0;
  19. }
  20.  
  21. int main() {
  22.     int i, size;
  23.  
  24.     printf("Enter the size of array: ");
  25.     scanf("%d", &size);
  26.  
  27.     int array[size];
  28.  
  29.     printf("\nEnter array values\n");
  30.     for (i = 0; i < size; i++) {
  31.         printf("%d. array element: ", i+1);
  32.         scanf("%d", &array[i]);
  33.     }
  34.  
  35.     int result = is123Array(array, size;
  36.  
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment