Wednesday, May 19, 2021

Finding the Largest Number in an Array in C

 Machine Problem 

Write a program for finding the largest number in an array.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website, kindly contact me also at my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.









Program Listing

/* largest.c

 Machine Problem
 
   Write a program for finding the largest number in an array.

Author : Jake Rodriguez Pomperada, MAED-IT, MIT
www.jakerpomperada.com  and www.jakerpomperada.blogspot.com
jakerpomperada@gmail.com
Bacolod City, Negros Occidental

*/

#include <stdio.h>

int main()
{
int *arr, i=0, j=0, num=0, LARGEST; 

printf("\n\n");
printf("\tFinding the Largest Number in an Array in C");
printf("\n\n");
printf("\tHow many elements in an array? : "); 
scanf("%d", &num);
printf("\n");
arr=(int*) malloc(sizeof(int)*num); 
for(i=0; i<num; i++)
{
printf("\tEnter a value number %d : ",i+1); 
scanf("%d", &arr[i]);
LARGEST=arr[0];
for(i=1; i<num;i++) 
{
if(arr[i]>LARGEST) LARGEST=arr[i];
}
printf("\n\n");
printf("\tThe largest number in the array is : %d", LARGEST); 
printf("\n\n");
printf("\tEnd of Program");
printf("\n\n");
system("pause");
}
 

No comments:

Post a Comment