Saturday, January 4, 2014

sum of .......

//sum of 1 to 100
int i,s=0;
for(i=1;i<=100;i++)
s=s+i;

//s contain 5050 which is sum of 1 to 100



//sum of 2+4+6+8+...+100
int i,s=0;
for(i=2;i<=100;i+=2)
s=s+i;

//s contain sum of 2+4+6+8+...+100




//sum of 3+7+11+15+...+79
int i,s=0;
for(i=3;i<=79;i+=4)
s=s+i;

//s contain sum of 3+7+11+15+...+79
 

No comments:

Post a Comment