标签:错误信息 src img 快速 for语句 优先 ima 保留 break
Input eps:1E-4
s = 0.835699
#include<stdio.h>
int main()
{
int flag,n;
double eps,item,s;
printf("Input eps: ");
scanf("%f",&eps);
flag = 1;
s = 0;
n = 1;
do{
item = 1/ n;
s = s + flag * item;
flag = -flag;
n = n + 3;
}while( item < eps)
printf( "s = %f\n",s);
return 0;
}
for(;;)是有指定次数的循环。两个都是循环结构
#include <stdio.h>
int main()
{
int s;
double sum=0,average,n=0;
{
for(;1;)
{
scanf("%d",&s);
if(s != -1)
{
sum=sum+s;
n=n+1;
}
else
{
break;
}
}
average=sum/n;
printf("%lf",average);
}
}
#include <stdio.h>
int main()
{
int s;
double sum=0,average,n=0;
{
while(1)
{
scanf("%d",&s);
if(s != -1)
{
sum=sum+s;
n=n+1;
}
else
{
break;
}
}
average=sum/n;
printf("%lf",average);
}
}
#include <stdio.h>
int main()
{
int s,i;
double sum=0,average,n=0;
scanf("%d",&i);
{
do
{
scanf("%d",&s);
if(s != -1)
{
sum=sum+s;
n=n+1;
}
else
{
break;
}
}while(n<i);
average=sum/n;
printf("%lf",average);
}
}
(1)
#include<stdio.h>
int main()
{
int n,s,i;
s = 0;
for(i = 1; i <= 10; i++)
{
scanf("%d",&n);
if(n % 2 == 0)
break;
s = s + n;
}
printf("s = %d\n",s);
return 0;
}
(2)
#include<stdio.h>
int main()
{
int n,s,i;
s = 0;
for(i = 1; i <= 10; i++)
{
scanf("%d",&n);
if(n % 2 == 0)
continue;
s = s + n;
}
printf("s = %d\n",s);
return 0;
}
#include <stdio.h>
int main(void)
{
double eps=0;
scanf("%lf",&eps);
int f=1,d=1;
double sum=0;
if(eps>=1)
{
printf("sum = 1.000000");
}
else
{
while((1.0/d)>=eps)
{
sum+=(1.0/d)*f;
f=-f;
d+=3;
}
printf("sum = %.6f",sum);
}
return 0;
}
#include<stdio.h>
int main()
{
int key, n;
scanf("%d %d",&key,&n);
int i;
int m;
int flag = 0;
for (i = 1;i <= n;i ++)
{
scanf("%d",&m);
if (m < 0)
break;
if (m > key)
printf("Too big\n");
if (m < key)
printf("Too small\n");
if (m == key)
{
if (i == 1)
{
flag = 1;
printf("Bingo!\n");
break;
}
if (i == 2 || i == 3)
{
flag = 1;
printf("Lucky You!\n");
break;
}
if (i > 3)
{
flag = 1;
printf("Good Guess!\n");
break;
}
}
}
if (flag == 0)
printf("Game Over\n");
return 0;
}
#include <stdio.h>
int main()
{
int n,s,sum;
sum=0;
scanf("%d",&s);
while(s > 0)
{
if(s%2!=0)
{
sum=sum+s;
}
scanf("%d",&s);
}
printf("%d",sum);
}
标签:错误信息 src img 快速 for语句 优先 ima 保留 break
原文地址:http://www.cnblogs.com/lipan123/p/7858162.html