Advertisement
Guest User

Für das Schwein!

a guest
Feb 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int checkArray(int a[],int length);
  4.  
  5. int main(void) {
  6.  
  7.     int array[9] = {1,2,2,1,2,3,3,2,1};
  8.     if(checkArray(array,9) == 1){
  9.         printf("Stimmt!");
  10.     }else{
  11.         printf("Stimmt nicht!");
  12.     }
  13.     return EXIT_SUCCESS;
  14. }
  15.  
  16. int checkArray(int a[],int length){
  17.     int durchlaeufe = length/3;
  18.     int index = 1;
  19.     for (int i=0;i<durchlaeufe;i++){
  20.         if(a[index] == a[index-1] || a[index] == a[index+1]){
  21.             return 0;
  22.         }
  23.         if(a[index-1] == a[index+1]){
  24.             return 0;
  25.         }
  26.     index = index+3;
  27.     }
  28.     return 1;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement