Que:
Write a program to accept 5 numbers in an array and find the maximum and minimum value of it.
Code:
#include <stdio.h>
void main()
{
int a[5],i,small,max;
printf("enter any 5 value\n");
for(i=0; i<5; i++)
{
scanf("%d", &a[i]);
}
small=a[0];
for(i=1;i<5;i++)
if (a[i]<small)
{
small=a[i];
}
max=a[0];
for(i=1;i<=5;i++)
if (a[i]>max)
{
max=a[i];
}
printf("small value is =%d \n",small);
printf("maximum value is =%d ",max);
}
Output:
Write a program to accept 5 numbers in an array and find the maximum and minimum value of it.
Code:
#include <stdio.h>
void main()
{
int a[5],i,small,max;
printf("enter any 5 value\n");
for(i=0; i<5; i++)
{
scanf("%d", &a[i]);
}
small=a[0];
for(i=1;i<5;i++)
if (a[i]<small)
{
small=a[i];
}
max=a[0];
for(i=1;i<=5;i++)
if (a[i]>max)
{
max=a[i];
}
printf("small value is =%d \n",small);
printf("maximum value is =%d ",max);
}
Output:
No comments:
Post a Comment