Write a program in C to display the n terms of square natural number and their sum


QUESTION:- Write a program in C to display the n terms of square natural number and their sum. 

1 4 9 16 ... n Terms 

Test Data : 

Input the number of terms : 5 

Expected Output : 

The square natural upto 5 terms are :1 4 9 16 25 

The Sum of Square Natural Number upto 5 terms = 55 


#include <stdio.h>

#include <conio.h>

void main()

{

    int noisum = 0a;

    printf("enter a value: ");

    scanf("%d", &no);

    for (i = 1i <= noi++)

    {

        a = i * i;

        printf("%d "a);

        sum = sum + a;
    }

    printf("\n%d is the sum "sum);

    getch();
}


OUTPUT

enter a value: 5

1 4 9 16 25


Follow our page for regular updates.

0 Comments