Program to find largest number in an array of one dimensional array
#include <stdio.h>
#define size 22
void main()
{
int a[size],i,n,max;
printf("\n Enter the size of an array : ");
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
printf("\n Array elements are : ");
for(i = 0; i < n; i++)
{
printf("\n Address : %p --> Array : a[%d] --> Data : %d ",&a[i],i,a[i]);
}
max=a[0];
for(i = 0; i < n; i++)
{
if(a[i]>max)
max=a[i];
}
printf("\n largest number in an array is %d",max);
}
output:
#include <stdio.h>
#define size 22
void main()
{
int a[size],i,n,max;
printf("\n Enter the size of an array : ");
scanf("%d",&n);
for(i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
printf("\n Array elements are : ");
for(i = 0; i < n; i++)
{
printf("\n Address : %p --> Array : a[%d] --> Data : %d ",&a[i],i,a[i]);
}
max=a[0];
for(i = 0; i < n; i++)
{
if(a[i]>max)
max=a[i];
}
printf("\n largest number in an array is %d",max);
}
output:
No comments:
Post a Comment