Answer to Question #198265 in C for Pragadees

Question #198265

Design a C program to find the

largest element of an array.


1
Expert's answer
2021-05-27T06:24:49-0400
#include <stdio.h>
#include <stdlib.h> 
#include <string.h> 


int main() {
	int values[1000];
	int i,n,largestElement;
	//get the number of values
	printf("Enter the number of values: ");
	scanf("%d",&n);
	fflush(stdin);
	//get the values from the user
	for(i=0; i<n; i++){
		printf("Enter the value [%d]: ",i);
		scanf("%d",&values[i]);	
	}
	//search the largest element of an array
	largestElement=values[0];
	for(i=1; i<n; i++){
		if(values[i]>largestElement){
			largestElement=values[i];
		}
	}
	//display the largest element of an array
	printf("\nThe largest element of an array is %d.\n\n",largestElement);


	getchar();
	getchar();


	return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS