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 no, i, sum = 0, a;
printf("enter a value: ");
scanf("%d", &no);
for (i = 1; i <= no; i++)
{
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
0 Comments