以下程序是计算1-3+5-7+~~~~-99+101的值:
main()
{ int i,s=0;
for(i=1;i<=101;i+=2)
{s=s+i;i=-i;}
printf("%d\n",s);
}
可为什么不对呢?
给你个范例 #include <stdio.h> #include <string.h> #include <conio.h>
int main() { /* Initalizing is a habit */ int len = 0; char buf[80]={0}; char *p = NULL,*end = NULL; char c = 0; /* Data exchange */ puts("Input a string"); gets(buf); p=buf; len=strlen(buf); end=p+len-1; /* Inverse */ while(p <= end) { c = *p; *p = *end; *end = c; p++; end--; } puts(buf); getch(); return 0; }