C program to find greatest element of an array
#include <stdio.h>
#include<conio.h>
int main()
{
int a[3];
int i;
//comparing arrays
elemment in position 0,1,2 using if statement
printf("Please enter only three elements :
\n");
for(i=0;i<3;i++){
scanf("%d",&a[i]);
}
if(a[0]>a[1]&&a[0]>a[2]){
printf("Element 1 is greater: ");
}
if(a[1]>a[2]&&a[1]>a[0]){
printf("Element 2 is greater: ");
}
if(a[2]>a[1]&&a[2]>a[0]){
printf("Element 3 is greater: ");
}
else
printf("Nothing to display:");
}
No comments:
Post a Comment