Dremendo Tag Line

Find sum of 1st 10 odd numbers using while loop in C

while Loop - Question 1

In this question, we will see how to find the sum of 1st 10 odd numbers in C programming using while loop. To know more about while loop click on the while loop lesson.

Q1) Write a program in C to find the sum of 1st 10 odd numbers using while loop.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int i=1,n=1,s=0;
    while(i<=10)
    {
        printf("%d\n",n);
        s=s+n;
        n=n+2;

        i=i+1;
    }
    printf("Sum of 1st 10 odd numbers = %d",s);
    return 0;
}

Output

1
3
5
7
9
11
13
15
17
19
Sum of 1st 10 odd numbers = 100
video-poster