check weather sum of digits of minimum element in the array is even or odd

// if even print 1 otherwise print 0

#include<stdio.h>
int get(int *arr,int n){
int min,i,rem,c=0;
min=arr[0];
for(i=1;i<n;i++)
if(arr[i]<min)
min=arr[i];
while(min!=0){
rem=min%10;
c=c+rem;
min=min/10;
}
if(c%2==0)
return 1;
else
return 0;
}
void main(){
int arr[100],n,i,j,sum;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
sum=get(arr,n);
printf("%d",sum);
}

Input:
6
62 13 21 55 61 72
Output:
1

No comments:

Post a Comment