Write a C program to find biggest of N numbers without using Arrays and using for loop.
Related Read:
For Loop In C Programming Language
Find Biggest of N Numbers, without using Arrays: C Program
Video Tutorial: C Program To Find Biggest of N Numbers, without using Arrays, using For Loop
[youtube https://www.youtube.com/watch?v=4B9i0l46g7I]
Logic To Find Biggest Number of N numbers, without using Arrays
We ask the user to enter the limit. i.e., the length of the list of numbers. For Example, if user enters limit value as 5, then we accept 5 numbers from the user and then find the biggest and output that number on to the console window.
First we ask the user to enter the limit. If user enters limit value as 5, we iterate the for loop 5 times i.e., until value of count is less than or equal to limit.
We check if its the first iteration of for loop. If true, we assign the first user entered number to variable big.
Inside the for loop, for each iteration we ask the user to enter a number. Next we check if that user entered number is greater than the value present in variable big. If the new number entered by the user is greater than value present in variable big, then we assign the new number entered by the user to the variable big. We keep doing this for each number entered by the user.
Source Code: C Program To Find Biggest of N Numbers, without using Arrays, using For Loop
#include<stdio.h> int main() { int limit, num, count, big; printf("Enter the limit\n"); scanf("%d", &limit); printf("Enter %d numbers\n", limit); for(count = 1; count <= limit; count++) { scanf("%d", &num); if(num > big || count == 1) { big = num; } } printf("Biggest number is %d\n", big); return 0; }
Output 1:
Enter the limit
5
Enter 5 numbers
1
9
3
7
4
Biggest number is 9
Output 2:
Enter the limit
6
Enter 6 numbers
-2
-5
-6
-9
-1
-4
Biggest number is -1
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert