C code to find largest and smallest number in an array

//C code to find largest and smallest number in an array
int main() {
	int a[50], size, i, big, small;
	printf("\nEnter the size of the array: ");
	scanf("%d", &size);
	printf("\nEnter %d elements in to the array: ", size);
	for (i = 0; i < size; i++)
		scanf("%d", &a[i]);
	big = a[0];
	for (i = 1; i < size; i++) {
		if (big < a[i])
			big = a[i];
	printf("Largest element: %d\n", big);
	small = a[0];
	for (i = 1; i < size; i++) {
		if (small > a[i])
			small = a[i];
	printf("Smallest element: %d\n", small);
	return 0;


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s