Advertisement
Lorenzo1818

Esercitazione3(4.0)

Oct 19th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int isPalindroma(int array[], int l){
  4.     if (l%2 == 1){
  5.         int lmetaArray = (int) l/2;
  6.         for(int i = 1; i <=lmetaArray; i++){
  7.             if (array[i-1] != array[l-i]){
  8.                 return 0;
  9.             }
  10.         }
  11.         return 1;
  12.     }
  13.     else {
  14.         for (int i = 1; i <l/2; i++){
  15.             if (array[i-1] != array[l-i]){
  16.                 return 0;
  17.             }
  18.         }
  19.         return 1;
  20.     }
  21. }
  22.  
  23. void main(){
  24.     int array[] = {1,2,3,3,3,1};
  25.     if (isPalindroma(array, 6)){
  26.         printf("La sequenza data e' palindroma.");
  27.     }
  28.     else {
  29.         printf("La sequenza data non e' palindroma.");
  30.     }
  31.     getchar();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement