用C语言编写求整数1到10的和
这个程序不用FOR语句,用最初学的C语言来写并在GCC3.2.2中运行.
第1个回答 推荐于2017-10-15
#include <stdio.h>
void main()
{
int i=0;
for(int j=1;j<=10;j++)
{
i+=j;
}
printf("%d\n",i);
}本回答被提问者采纳
void main()
{
int i=0;
for(int j=1;j<=10;j++)
{
i+=j;
}
printf("%d\n",i);
}本回答被提问者采纳
第2个回答 2009-09-09
#include<stdio.h>
int main(){
int i,s;s=0;
for(i=1;i<=10;i++)
s+=i;
printf("%d",s);
}
int main(){
int i,s;s=0;
for(i=1;i<=10;i++)
s+=i;
printf("%d",s);
}
第3个回答 2009-09-22
......
#include<stdio.h>
int main(void)
{
int a=55;
printf("整数1到10的和为:%d\n",a);
getchar();
return 0;
}
#include<stdio.h>
int main(void)
{
int a=55;
printf("整数1到10的和为:%d\n",a);
getchar();
return 0;
}
第4个回答 2009-09-22
#include<stdio.h>
void main()
{
int i,s;
s=1+2+3+4+5+6+7+8+9+10;
printf("%d\n",s);
}
void main()
{
int i,s;
s=1+2+3+4+5+6+7+8+9+10;
printf("%d\n",s);
}
第5个回答 2009-09-09
#include <stdio.h>
void main()
{
//首项加末项乘项数除以2
int i;
i=(1+10)*10/2;
printf("%d\n",i);
}
void main()
{
//首项加末项乘项数除以2
int i;
i=(1+10)*10/2;
printf("%d\n",i);
}
参考资料: