C Program to find Greatest number in Array

Let’s write a program which print Greatest number in Array in C.

 

Step 1: Let’s open Turbo C and write the following code.

 

//Code

 

//Add Preprocessor File

 

#include<stdio.h>

#include<conio.h>

void main()

{

//Declare variable

long int i,a[5],max;

 

//Clear screen

clrscr();

 

printf(“ \n enter all numbers :”);

for(i=0;i<5;i++)

{

scanf(“%li”,&a[i]);

}

max=a[0];

for(i=0;i<5;i++)

{

if(max<a[i])

{

max=a[i];

}

}

 

//print the result

printf(“\n greatest number is : %li”,a[i]);

 

getch();

}

 

Step 2: Now save it by pressing F2 ,and name it GREATEST.CPP and click OK.

 

 

 

Step 3: Now compile it by pressing ALT+F9 or click on compile.

 

 

 

Step 4: Run the program by pressing ALT+R and press enter and see output.

 

 

 

Output:

 

 

OUTPUT

 

Happy coding.

 

 

 

 

 

 

 

Tags: , , ,