Short Note
WAP to print the sum of following series.
1+22+33+………+nn
Advertisement Remove all ads
Solution
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0;
clrscr();
printf("Enter a number ");
scanf("%d",&n);
while(n!=0)
{
sum=sum+(n*n);
n--;
}
printf("The sum of the series is %d",sum);
getch ();
}
Output: |
Concept: Control Structures - Looping
Is there an error in this question or solution?
Advertisement Remove all ads
APPEARS IN
Advertisement Remove all ads
Advertisement Remove all ads