while loop
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b=0;
clrscr();
while(a<=9)
{
b=b+2;
printf("%d\n",b);
a++;
}
getch();
}
Output:
2
4
6
8
10
12
14
16
18
20
-----------------------------
A program of the sum of the series 1+2×2+3×3+4×4+…………+n×n
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j;
int n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
while(j<=n)
{
i=i+j*j;
j++;
}
printf("Sum=%d",i);
getch();
}
Output:
Enter the value of n:4
Sum=30
---------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j=1;
int n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
printf("The series=\n");
while(j<=n-1)
{
printf("%d+",j*j);
i=i+j*j;
j++;
}
printf("%d",n*n);
i=i+n*n;
printf("\nSum=%d",i);
getch();
}
Output:
Enter the value of n:4
The series=
1+4+9+16
Sum=30
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b=0;
clrscr();
while(a<=9)
{
b=b+2;
printf("%d\n",b);
a++;
}
getch();
}
Output:
2
4
6
8
10
12
14
16
18
20
-----------------------------
A program of the sum of the series 1+2×2+3×3+4×4+…………+n×n
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j;
int n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
while(j<=n)
{
i=i+j*j;
j++;
}
printf("Sum=%d",i);
getch();
}
Output:
Enter the value of n:4
Sum=30
---------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j=1;
int n;
clrscr();
printf("Enter the value of n:");
scanf("%d",&n);
printf("The series=\n");
while(j<=n-1)
{
printf("%d+",j*j);
i=i+j*j;
j++;
}
printf("%d",n*n);
i=i+n*n;
printf("\nSum=%d",i);
getch();
}
Output:
Enter the value of n:4
The series=
1+4+9+16
Sum=30

No comments:
Post a Comment