问什么结果不对,哪里出错了
求1+3+5+....+2n-1+...的值#include<stdio.h>
main()
{
int i,n,sum;
printf("please input n:\n");
scanf("%d",&n);
for (i=1;i<=n;i+2)
sum=0;
sum=sum+i;
printf("%d",sum);
}
#include <stdio.h> int main(int argc, char* argv[]) { int i,n,sum=0; start: printf("please input n:\n"); scanf("%d",&n); if(n%2==0) { printf("输入错误 请重新输入"); goto start; } for(i=1;i<=n;i+=2) { sum+=i; } printf("1+3+5+...%d=%d\n",n,sum); return 0; }