Jan 30, 2014

C program for finding the largest number in an array


#include<stdio.h>
#include<conio.h>

void main()
{
int *arr, i, j, n, LARGE;
clrscr();
printf(“Enter the number of elements in the array”);
scanf(“%d”, &n);
arr=(int*) malloc(sizeof(int)*n);
for(i=0; i<n; i++)
{
printf(“Enter a number”);
scanf(“%d”, &arr[i]);
}
LARGE=arr[0];
for(i=1; i<n;i++)
{
if(arr[i]>LARGE)
LARGE=arr[i];
}
printf(“The largest number in the array is : %d”, LARGE);
getch();
}

0 comments:

Post a Comment