Q: program to print total of 1-2+3-4+5-6+7....
#include
#include
void main()
{
int k,sum=0;
clrscr();
for(k=1;k<=10;k++)
{
if(k%2==1)
sum=sum+k;
else
sum=sum-k;
}
printf("sum=%d ",sum);
getch();
}
This blog is for the struggling programmers who need assitance..
No comments:
Post a Comment