Greatest Number Finder
Welcome to another exciting coding adventure! In this blog post, we're diving headfirst into the realm of programming with a C program that's all about finding the greatest among a group of numbers. Whether you're new to coding or an experienced enthusiast, you're in for a treat. We'll unravel the intricacies of the program step by step, shedding light on how it identifies the biggest number from a given set. So, if you're eager to enhance your coding skills and explore the world of C programming, let's get started on this fascinating journey of discovery!
Explore how to write a C program that finds the greatest number among 10 given numbers using this informative guide.
#include <stdio.h>
int main() {
int numNumbers = 10;
int greatest = 0;
for (int i = 1; i <= numNumbers; i++) {
int number;
printf("Enter number %d: ", i);
scanf("%d", &number);
if (i == 1 || number > greatest) {
greatest = number;
}
}
printf("The greatest number is: %d\n", greatest);
return 0;
}
Test the Program
Enter 10 numbers (one per line):
Explanation
-
Step 1:
The program starts by including the standard input/output library
stdio.h
. -
Step 2:
In the
main()
function, integer variablesnumNumbers
andgreatest
are declared. -
Step 3:
A
for
loop is used to input 10 numbers and find the greatest among them. - Step 4: The program checks if the current number is greater than the current greatest number found.
-
Step 5:
The program displays the greatest number using
printf()
.
If you have any doubts, Please let me know