Answers for "write a c program to input n numbers and find the largest number"

4

find the largest number among five numbers in c language

#include<stdio.h> 
 
int main() 
{ 
 int a,b,c,d,e; 
 
 printf("ENTER THE FIVE NUMBERS"); 
 scanf("%d %d %d %d %d",&a,&b,&c,&d,&e); 
 
 if(a>b && a>c &&  a>d && a>e) 
  printf("%d is largest", a); 
 
 else 
  if(b>c && b>d && b>e) 
   printf("%d is largest", b); 
 
 else 
  if(c>d && c>e) 
   printf("%d is largest", c); 
 
 else 
  if(d>e) 
   printf("%d  is largest", d); 
 
 else 
  printf("%d is largest", e); 
  
 return 0; 
}
Posted by: Guest on December-30-2021
1

c program to print the largest number in an array

//simple c program to print smallest and largest number in an array
int main(){
int i,marks[10],num,sum;
printf("enter number of elements:");
scanf("%d",&num);

printf("enter %d elements:",num);
for(i=0;i<num;i++){
scanf("%d",&marks[i]);
}
printf("the smallest number is:%d\n ",marks[0]);
//largest number for loop
  for (int i = 1; i < num; i++) {
    if (marks[0] < marks[i]) {
      marks[0] = num;
    }
  }

printf("the largest number is:%d\n ",marks[0]);
return 0;
}
Posted by: Guest on March-09-2022

Code answers related to "write a c program to input n numbers and find the largest number"

Browse Popular Code Answers by Language