C Program To Find Biggest of N Numbers, without using Arrays, using For Loop

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]

YouTube Link: https://www.youtube.com/watch?v=4B9i0l46g7I [Watch the Video In Full Screen.]


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

C Program To Calculate Sum and Average of N Numbers without using Arrays, using For Loop

Write a C program to calculate Sum and Average of N numbers without using Arrays and using for loop.

Related Read:
Basic Arithmetic Operations In C
For Loop In C Programming Language
Calculate Sum and Average of N Numbers without using Arrays: C Program

Video Tutorial: C Program To Calculate Sum and Average of N Numbers without using Arrays, using For Loop


[youtube https://www.youtube.com/watch?v=Xif47CU4VUY]

YouTube Link: https://www.youtube.com/watch?v=Xif47CU4VUY [Watch the Video In Full Screen.]


Logic To Calculate Sum and Average of N Numbers without using Arrays

We ask the user to input the limit. Based on that limit value we ask the user to enter the integer numbers. For example, if the user enters value of limit as 5, then we ask the user to enter 5 integer numbers.

If limit is 5, then inside for loop we ask the user to input 5 integer values, and we add those values to the previous value present in variable sum. Simultaneously we keep incrementing the value of variable count by 1 for each iteration of for loop. Once the value of variable count is greater than the value of limit, then the control exits for loop. Immediately outside for loop we calculate the average by using the formula:

average = sum / limit;

Source Code: C Program To Calculate Sum and Average of N Numbers without using Arrays, using For Loop

#include<stdio.h>

int main()
{
    int num, count, sum = 0;
    float avg = 0.0, limit;

    printf("Enter the limit\n");
    scanf("%f", &limit);

    printf("Enter %f numbers\n", limit);
    for(count = 1; count <= limit; count++)
    {
        scanf("%d", &num);
        sum = sum + num;
    }
    avg = sum / limit;

    printf("Sum = %d\nAverage = %0.2f\n", sum, avg);

    return 0;
}

Output 1:
Enter the limit
6
Enter 6 numbers
1
5
9
3
5
7
Sum = 30
Average = 5.00

Output 2:
Enter the limit
14
Enter 14 numbers
5
6
3
2
1
4
9
7
8
0
-5
-6
0
-10
Sum = 24
Average = 1.71

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

C Program To Find Sum of All Even Numbers Between Range, using For loop

Lets write a C program to find sum of all the even numbers between range or between 2 integers input by the user, using for loop.

Even Number: An even number is an integer that is exactly divisible by 2.

For Example: 14 % 2 == 0. When we divide 14 by 2, it gives a reminder of 0. So number 14 is an even number.

Note: In this C program we ask the user to input start and end value. We assume that the user enters bigger value for variable end and smaller value for variable start. i.e., start < end If start value is greater than value present in end, we swap the values of variable start and end.

If user enters start = 5 and end = 14. C program finds all the even numbers between 5 and 14, including 5 and 14. So the even numbers are 6, 8, 10, 12, 14. We add all these even numbers and output the sum to the console window. i.e., 6 + 8 + 10 + 12 + 14 = 50. We out put the value 50 as result.

Related Read:
Decision Control Instruction In C: IF
For Loop In C Programming Language
Even or Odd Number: C Program
C Program to Generate Even Numbers Between Two Integers

You can also watch C Program To Find Sum of All Even Numbers Between Two Integers, using While loop

Video Tutorial: C Program To Find Sum of All Even Numbers Between Range, using For loop


[youtube https://www.youtube.com/watch?v=9nKzyNnM2CY]

YouTube Link: https://www.youtube.com/watch?v=9nKzyNnM2CY [Watch the Video In Full Screen.]

Logic To Find Sum of All Even Numbers Between Range, using For loop

Step 1: We ask the user to enter start and end value.

Step 2: We initialize count to start and iterate through the for loop until value of count is less than or equal to value of variable end. For each iteration of for loop count value increments by 1.

Step 3: For every iteration we check if value present in variable count is a even number. i.e., count % 2 == 0. If this condition is true, then we add the value present in variable count to the previous value of variable sum.

Step 4: Once the control exits for loop, we print the value present in variable sum – which has the sum of all the even numbers between the range entered by the user.

Source Code: C Program To Find Sum of All Even Numbers Between Range, using For loop

#include<stdio.h>

int main()
{
    int start, end, temp, count, sum = 0;

    printf("Enter start and end values\n");
    scanf("%d%d", &start, &end);

    if(start > end)
    {
        temp  = start;
        start = end;
        end   = temp;
    }

    printf("Even numbers between %d and %d are:\n", start, end);
    for(count = start; count <= end; count++)
    {
        if(count % 2 == 0)
        {
            printf("%d\n", count);
            sum = sum + count;
        }
    }

    printf("Sum of all the even numbers from %d to %d is %d\n", start, end, sum);

    return 0;
}

Output 1:
Enter start and end values
5
14
Even numbers between 5 and 14 are:
6
8
10
12
14
Sum of all the even numbers from 5 to 14 is 50

Output 2:
Enter start and end values
23
14
Even numbers between 14 and 23 are:
14
16
18
20
22
Sum of all the even numbers from 14 to 23 is 90

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

C Program To Find Sum of All Odd Numbers Between Range, using For loop

Lets write a C program to find sum of all odd numbers between range or between 2 integers input by the user, using For loop.

Odd Number: An odd number is an integer that is not exactly divisible by 2.

For Example: 15 % 2 != 0. When we divide 15 by 2, it does not give a reminder of 0. So number 15 is an odd number.

Note: In this C program we ask the user to input start and end value. We assume that the user enters bigger value for variable end and smaller value for variable start. i.e., start < end If not, we swap the values of variable start and end.

If user enters start = 14 and end = 23. C program finds all the odd numbers between 14 and 23, including 14 and 23. So the odd numbers are 15, 17, 19, 21, 23. We add all these odd numbers and output the sum to the console window. i.e., 15 + 17 + 19 + 21 + 23 = 95. We out put the value 95 as result.

Related Read:
Decision Control Instruction In C: IF
For Loop In C Programming Language
Even or Odd Number: C Program
C Program to Generate Odd Numbers Between Two Integers

Video Tutorial: C Program To Find Sum of All Odd Numbers Between Range, using For loop


[youtube https://www.youtube.com/watch?v=tUudL6AKPOg]

YouTube Link: https://www.youtube.com/watch?v=tUudL6AKPOg [Watch the Video In Full Screen.]

Logic To Find Sum of All Odd Numbers Between Range, using For loop

Step 1: We ask the user to enter start and end value.

Step 2: Variable count is initialized to start and for loop executes until count is less than or equal to end. For each iteration of the for loop, value of count increments by 1.

Step 3: For every iteration of the for loop, we check if value present in variable count is an odd number. i.e., count % 2 != 0. If this condition is true, then we add the value present in variable count to the previous value of variable sum.

Step 4: Once the control exits for loop, we print the value present in variable sum – which has the sum of all the odd numbers between the range entered by the user.

Source Code: C Program To Find Sum of All Odd Numbers Between Range, using For loop

#include<stdio.h>

int main()
{
    int start, end, temp, count, sum = 0;

    printf("Enter start and end value\n");
    scanf("%d%d", &start, &end);

    if(start > end)
    {
        temp  = start;
        start = end;
        end   = temp;
    }

    printf("Odd numbers from %d to %d are\n", start, end);
    for(count = start; count <= end; count++)
    {
        if(count % 2 != 0)
        {
            printf("%d\n", count);
            sum = sum + count;
        }
    }

    printf("Sum of all the Odd numbers from %d to %d is %d\n", start, end, sum);

    return 0;
}

Output 1:
Enter start and end value
5
14
Odd numbers from 5 to 14 are
5
7
9
11
13
Sum of all the Odd numbers from 5 to 14 is 45

Output 2:
Enter start and end value
14
23
Odd numbers from 14 to 23 are
15
17
19
21
23
Sum of all the Odd numbers from 14 to 23 is 95

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

C Program To Find Sum of All Odd Numbers From 1 To N, using For loop

Lets write a C program to find sum of all the odd numbers from 1 to N, using for loop.

Odd Number: An odd number is an integer that is not exactly divisible by 2.

For Example: 7 % 2 != 0. When we divide 7 by 2, it doesn’t give a reminder of 0. So number 7 is odd number.

Related Read:
Decision Control Instruction In C: IF
For Loop In C Programming Language
Even or Odd Number: C Program

You can also watch the video for C Program To Find Sum of All Odd Numbers From 1 To N, using While loop

Video Tutorial: C Program To Find Sum of All Odd Numbers From 1 To N, using For loop


[youtube https://www.youtube.com/watch?v=pTkqSDPeCAc]

YouTube Link: https://www.youtube.com/watch?v=pTkqSDPeCAc [Watch the Video In Full Screen.]

Logic To Find Sum of All Odd Numbers From 1 To N, using For loop

Since we are checking for odd numbers from 1 to user entered number. We assign value of variable count to 1. For loop keeps iterating until value of count is less than or equal to user input number. For each iteration of for loop we increment the value of count by 1.

Inside for loop we check for the condition, count%2 != 0. If it’s true, then we add the value present inside variable count to previous value present in variable sum.

After the control exits for loop we display the value present in variable sum – which has the sum of all the odd numbers from 1 to user entered number.

Source Code: C Program To Find Sum of All Odd Numbers From 1 To N, using For loop

#include<stdio.h>

int main()
{
    int count, num, sum = 0;

    printf("Enter the limit\n");
    scanf("%d", &num);

    printf("Odd numbers from 1 To %d are:\n", num);
    for(count = 1; count <= num; count++)
    {
        if(count % 2 != 0)
        {
            printf("%d\n", count);
            sum = sum + count;
        }

    }

    printf("Sum of odd numbers from 1 To %d is %d\n", num, sum);

    return 0;
}

Output 1:
Enter the limit
5
Odd numbers from 1 To 5 are:
1
3
5
Sum of odd numbers from 1 To 5 is 9

Output 2:
Enter the limit
10
Odd numbers from 1 To 10 are:
1
3
5
7
9
Sum of odd numbers from 1 To 10 is 25

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