8. (A) Write a program to find the largest value that is stored in the array.

8. (A) Write a program to find the largest value that is stored in the array.
Write a program to find the largest value that is stored in the array.


#include <stdio.h>
int main(){
int i,n;
float arr[100];
printf("Enter total number of elements(1 to 100): ");
scanf("%d",&n);
printf("\n");
for(i=0;i<n;++i) /* Stores number entered by user. */
{
printf("Enter Number %d: ",i+1);
scanf("%f",&arr[i]);
}
for(i=1;i<n;++i) /* Loop to store largest number to arr[0] */
{
if(arr[0]<arr[i]) /* Change < to > if you want to find smallest element*/
arr[0]=arr[i];
}
printf("Largest element = %.2f",arr[0]);
return 0;
}
8. (A) Write a program to find the largest value that is stored in the array. 8. (A) Write a program to find the largest value that is stored in the array. Reviewed by admin on December 23, 2019 Rating: 5

No comments:

Powered by Blogger.