ProAnswers.org

C program to find the greatest among ten numbers

2 Likes

Program:

#include <stdio.h>
int main()
{
 int a[10];
 int i;
 int greatest;
 printf("Enter ten values:");
 //Store 10 numbers in an array
 
for (i = 0; i < 10; i++)
{
  scanf("%d", &a[i]);
 }
 //Assume that a[0] is greatest
 greatest = a[0];

 for (i = 0; i < 10; i++)
{
  if (a[i] > greatest)
{
   greatest = a[i];
  }
 }
 
printf("\nGreatest of ten numbers is %d", greatest);
 return 0;
}

Output:
Enter ten values: 2 53 65 3 88 8 14 5 77 64 Greatest of ten numbers is 88

#include<stdio.h>
void main()
{
int n,i;
printf("enter a,a1,a2,a3,a4,a5,a6,a7,a8,a9 numbers");
scanf("%d5d%d%d%d%d%d%d%d%d",&a,&a1,7a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9);
if(a>a1&&a>a2&&a>a3&&a>a4&&a>a5&&a>a6&&a>a7&&a>a8&&a>a9)
{
printf(" a is the greater number",a);
}
else
if(a1>a&&a1>a2&&a1>a3&&a1>a4&&a1>a5&&a1>a6&&a1>a7&&a1>a8&&a1>a9)
{
printf(" a1 is the greater number",a1);
}
else if(a2>a&&a2>a1&&a2>a3&&a2>a4&&a2>a5&&a2>a6&&a2>a7&&a2>a8&&a2>a9)
{
printf(" a2 is the greater number",a2);
}

.........................
....................
...........................
....................similarly



else if(a8>a1&&a8>a2&&a8>a3&&a8>a4&&a8>a5&&a8>a6&&a8>a7&&a8>a&&a8>a9)
{
printf(" a8 is the greater number",a8);
}
else if(a9>a1&&a9>a2&&a9>a3&&a9>a4&&a9>a5&&a9>a6&&a9>a7&&a9>a8&&a9>a)
{
printf(" a9 is the greater number",a9);
}
else
printf("a9 is the greatest no'r");
}