logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • Contact

Questions & Answers

C Interview Questions
C++ Questions
Linux MCQs
C# Quiz
Java MCQs
JavaScript MCQs
SAN Questions
PHP Questions
Python Quiz

Computer Science Questions

Operating System Quiz
Computer Architecture MCQs
Software Architecture MCQs
Software Engineering MCQs
Artificial Intelligence MCQs
LISP Programming MCQs
Database Management MCQs
Computer Network MCQs
Microprocessor MCQs

C Programming Examples

Simple C Programs
C - Arrays
C - Matrix
C - Strings
C - Bitwise Operations
C - Linked Lists
C - Stacks & Queues
C - Searching & Sorting
C - Trees
C - Strings
C - File Handling
C - Mathematical Functions
C - Puzzles & Games
C Programs - Recursion
C Programs - No Recursion

Java Algorithms

Java - Numerical Problems
Java - Combinatorial Problems
Java - Graph Problems
Java - Hard Graph Problems
Java - Computation Geometry
Java - Sets & Strings
Java - Data-Structures
Java - Collection API Problems

C++ Algorithms

C++ - Numerical Problems
C++ - Combinatorial Problems
C++ - Graph Problems
C++ - Hard Graph Problems
C++ - Computation Geometry
C++ - Sets & Strings
C++ - Data-Structures
C++ - STL Library

C Algorithms

C - Numerical Problems
C - Combinatorial Problems
C - Graph Problems
C - Hard Graph Problems
C - Computation Geometry
C - Sets & Strings
C - Data-Structures

« Prev Page
Next Page »

C Program to Find the Largest Number in an Array

Posted on January 29, 2013 by Manish

This is a C Program to find the largest number in an array.

Problem Description

This program will implement a one-dimentional array and find out the largest element present in the array.

Problem Solution

1. Create an array of fixed capacity.
2. Taking size of the array as input from users, run the for loop till the size to insert element at each location.
3. Considering the first element of the array to be the largest, compare all the remaining elements of array, and change the largest value if assumed largest element is smaller than the comparing element.
4. At last, the largest element will hold the actual largest value in the array. Thus, print it.

advertisement
Program/Source Code

Here is source code of the C Program to find the largest number in an array. The program is successfully compiled and tested using Turbo C compiler in windows environment. The program output is also shown below.

  1. /*
  2.  * C Program to Find the Largest Number in an Array
  3. */
  4.  
  5. #include <stdio.h>
  6.  
  7. int main()
  8. {
  9.  
  10.         int array[50], size, i, largest;
  11.  
  12.         printf("\n Enter the size of the array: ");
  13. 	scanf("%d", &size);
  14.  
  15.         printf("\n Enter %d elements of  the array: ", size);
  16.  
  17.         for (i = 0; i < size; i++)
  18. 		scanf("%d", &array[i]);
  19.  
  20.         largest = array[0];
  21.  
  22.         for (i = 1; i < size; i++) 
  23.         {
  24. 		if (largest < array[i])
  25. 			largest = array[i];
  26. 	}
  27.  
  28.         printf("\n largest element present in the given array is : %d", largest);
  29.  
  30.         return 0;
  31.  
  32. }
Program Explanation

1. Create an integer array of capacity 50.
2. Take size of the array as input from users.
3. Using for loop, take array element as input from users and insert into the array.
4. After inserting all the elements of the array, consider the very first element of array to be the largest.
5. Run a for loop, from 1 to arraySize-1, extracting array element one by one and comparing it to the largest element.
6. If largest element is smaller than the comparing element of array, then the largest element is updated to current element of array.
7. At the end, the largest element will hold the actual largest value present in the array.

advertisement
Runtime Test Cases
Enter the size of the array: 5
 
Enter 5 elements of  the array: 12
56
34
78
100
 
largest element present in the given array is : 100

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Reference Books in C Programming, Data Structures and Algorithms.

« Prev Page - C Program to Print the kth Element in the Array
» Next Page - C Program to Find the Number of Elements in an Array

« C Program to Print the kth Element in the Array
C Program to Find the Number of Elements in an Array »

Deep Dive @ Sanfoundry:

  1. C Programming Examples on Searching and Sorting
  2. C Programming Examples on Linked List
  3. C# Programming Examples on Data Structures
  4. C# Programming Examples on Sorting
  5. C# Programming Examples on Matrix
  6. C# Programming Examples on Arrays
  7. Java Programming Examples on Arrays
  8. C Programming Examples on Stacks & Queues
  9. Java Programming Examples on Collections
  10. C Programming Examples on Arrays
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.