#include <stdio.h>
int main()
{
int sum,couth;
sum=0;
couth=1;
while(couth<=100)
{
sum=sum+couth;
couth=couth+1;
}
printf("1+2+3+...+100的值是%d",sum);
return 0;
}
接下来举一反三,来计算1-100中偶数相加的和。
#include <stdio.h>
int main()
{
int sum,couth;
sum=0;
couth=2;
while(couth<=100)
{
sum=sum+couth;
couth=couth+2;
}
printf("1-100的偶数和是%d",sum);
return 0;
}
#include <stdio.h>
int main()
{
printf("a\tc\n");
printf("d\te\rf\f");
return 0;
}
#include <stdio.h>
int main()
{
double a,b,c,f;
scanf("%lf,%lf,%lf",&a,&b,&c);
if(a>b)
{
f=a;
a=b;
b=f;
}
if(a>c)
{
f=a;
a=c;
c=f;
}
if(b>c)
{
f=b;
b=c;
c=f;
}
printf("a,b,c从小到大是%f,%f,%f",a,b,c);
return 0;
}
|