C Program To Print 1+4+9+16 Series, using While Loop

Lets write C program to print/display number series 1 + 4 + 9 + 16 + 25 + using while loop.

Logic To Print 1+4+9+16 number series using while loop

If we analyze the number series, its just addition of square of natural numbers. i.e., (1 x 1) + (2 x 2) + (3 x 3) + (4 x 4) + (5 x 5) + .. etc

We ask the user to enter a number. If user enters num = 5, then we display the first 5 numbers in the series i.e., 1 + 4 + 9 + 16 + 25 +

If user enters num = 10, then we display the first 10 numbers in the series i.e., 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 +

Related Read:
while loop in C programming

Video Tutorial: C Program To Print 1+4+9+16+25 Series, using While Loop



YouTube Link: https://www.youtube.com/watch?v=7WW17-nW-8k [Watch the Video In Full Screen.]

Source Code: C Program To Print 1+4+9+16 Series, using While Loop

#include<stdio.h>

int main()
{
    int num, count = 1;

    printf("Enter a integer number greater than 1\n");
    scanf("%d", &num);

    while(count <= num)
    {
        printf("%d + ", (count*count));
        count++;
    }

    return 0;
}

Output 1:
Enter a integer number greater than 1
5
1 + 4 + 9 + 16 + 25 +

Output 2:
Enter a integer number greater than 1
10
1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100 +

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