fork download
  1.  
  2. int divisor(int a, int b){
  3. int gcd = 1;
  4. for (int i = 1; i <= a && i <= b; i++) {
  5. if (a % i == 0 && b % i == 0) {
  6. gcd = i;
  7. }
  8. }
  9. if(gcd <= 1){
  10. return 1;
  11. }
  12. else{
  13. return 0;
  14. }
  15.  
  16. }
  17.  
  18. int check(int *array, int length){
  19. for (int i = 0; i < length - 1; i++) {
  20. if (array[i] > array[i + 1] && divisor(array[i], array[i + 1])==1) {
  21. return i;
  22. }
  23. }
  24. }
  25.  
  26. void main(){
  27. int noOfCities;
  28. printf("Enter the no. of cities : ");
  29. scanf("%d",&noOfCities);
  30. int percentage[noOfCities];
  31. printf("Enter the percentage of zombies");
  32. for(int i =0; i<noOfCities;i++){
  33. scanf("%d",&percentage[i]);
  34. }
  35. printf("favarouble city index: %d",check(percentage,noOfCities));
  36. }
Success #stdin #stdout 0s 5548KB
stdin
Standard input is empty
stdout
Enter the no. of cities : Enter the percentage of zombiesfavarouble city index: 4313