0% found this document useful (0 votes)
57 views2 pages

Series C

CS

Uploaded by

Anurag Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views2 pages

Series C

CS

Uploaded by

Anurag Goel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Series

s=1+2+3+...n

#include<stdio.h>
void main()
{
int i,n,s=0;
printf("Enter n");
scanf("%d",&n); 10
for(i=1;i<=n;i++) 1 2 3 4 5 6 7 8 9 10
{
s=s+i; 0+1=1 1+2=3 3+3=6 6+4=10 10+5=15 15+6=21
21+7=28 28+8=36 36+9=45 45+10=55
}
printf("\ns=%d",s); 55
}
---------------------------------
s=1+1/2+1/3+...1/n

#include<stdio.h>
void main()
{
int i,n;
float s=0;
printf("Enter n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s=s+1/i;
}
printf("\ns=%f",s);
}
---------------------------------
s=1^2+2^2+3^2+...n^2

#include<stdio.h>
void main()
{
int i,n,s=0;
printf("Enter n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s=s+i*i;
}
printf("\ns=%d",s);
}
----------------------------------
s=2+4+6+...n

#include<stdio.h>
void main()
{
int i,n,s=0;
printf("Enter n");
scanf("%d",&n); 10
for(i=2;i<=n;i+=2) 2 4 6 8 10
{
s=s+i; 0+2=2 2+4=6 6+6=12 12+8=20 20+10=30
}
printf("\ns=%d",s); 30
}
----------------------------------
int i;
for(i=1;i<=10;i++)
{
if(i%7==0) or if(i==7)
{
break; Loop will be terminated
}
else
{
printf("%d\t",i);
}
}

1 2 3 4 5 6
-----------------------------------------
int i;
for(i=1;i<=10;i++)
{
if(i==3)
{
continue; Loop will begin from 1 then skip 3 and continue with 4 onwards
}
else
{
printf("%d\t",i);
}
}

1 2 4 5 6 7 8 9 10
------------------------------------------------------------------
int i;
for(i=1;i<=10;i++)
{
if(i%3==0)
{
continue;
}
else
{
printf("%d\t",i);
}
}

1 2 4 5 7 8 10
--------------------------------------------------

You might also like