解析:
参考代码:
#include
//方法1
int main()
{
int iq = 0;
while(scanf("%d", &iq) != EOF)
{
if(iq>=140)
printf("Genius");
}
return 0;
}
//方法2
#include
int main()
{
int iq = 0;
//这种写法是因为scanf读取失败返回EOF,EOF是-1,
//所以按位取反后的结果是0, 0为假,可以让循环停止。
while(~scanf("%d", &iq))
{
if(iq>=140)
printf("Genius");
}
return 0;
}
解析:
参考代码:
//代码一
#include
int main()
{
int score = 0;
while(scanf("%d", &score) != EOF)
{
if(score >= 90 && score<=100)
printf("Perfect");
}
return 0;
}
//代码二
#include
int main()
{
int score = 0;
while(~scanf("%d", &score))
{
if(score >= 90 && score<=100)
printf("Perfect");
}
return 0;
}
参考代码:
#include
int main()
{
int score = 0;
while(scanf("%d", &score) != EOF)
{
if(score >= 60)
printf("Pass\n");
else
printf("Fail\n");
}
return 0;
}
参考代码:
//代码一
#include
int main()
{
int num = 0;
while(scanf("%d", &num) != EOF)
{
if(num%2==1)
printf("Odd\n");
else
printf("Even\n");
}
return 0;
}
//代码二
#include
int main()
{
int num = 0;
while(~scanf("%d", &num))
{
if(num%2==1)
printf("Odd\n");
else
printf("Even\n");
}
return 0;
}
解析:
参考代码:
//代码一
#include
int main()
{
int i = 0;
int score[3] = {0};
while(scanf("%d %d %d", &score[0], &score[1], &score[2]) != EOF)
{
int max = 0;//每一组测试,max都恢复到0
int i = 0;
for(i=0; i<3; i++)
{
if(score[i] > max)
max = score[i];
}
printf("%d\n", max);
}
return 0;
}
//代码二
#include
int main()
{
int n1 = 0;
int n2 = 0;
int n3 = 0;
while(~scanf("%d %d %d", &n1, &n2, &n3))
{
int max = n1>n2?n1:n2;
max = max>n3?max:n3;
printf("%d\n", max);
}
return 0;
}
解析:
参考代码:
//方法1
#include
int main()
{
char ch = 0;
//存放元音字母的数组
char vowel[] = "AaEeIiOoUu";
//输入
while((ch=getchar()) != EOF)
{
//判断
int i = 0;
for(i=0; i<10; i++)
{
if(ch == vowel[i])
{
printf("Vowel\n");
break;
}
}
if(i == 10)
{
printf("Consonant\n");
}
getchar();//去除每个字符后的\n
}
return 0;
}
//方法2
#include
int main()
{
char ch = 0;
char arr[] = "AEIOUaeiou";
//在%c的前面写一个空格会消化掉前面所有的空白字符,然后读取一个字符
while(scanf(" %c", &ch) != EOF)
{
int i = 0;
for(i=0; i<10; i++)
{
if(ch == arr[i])
{
printf("Vowel\n");
break;
}
}
if(i == 10)
printf("Consonant\n");
}
return 0;
}
//方法3
#include
int main()
{
char ch = 0;
char arr[] = "AEIOUaeiou";
//在%c的后边发给一个'\n',其实在输入时候就会消化掉这个\n字符
//不会为下次留下空白字符的隐患
while(scanf("%c\n", &ch) != EOF)
{
int i = 0;
for(i=0; i<10; i++)
{
if(ch == arr[i])
{
printf("Vowel\n");
break;
}
}
if(i == 10)
printf("Consonant\n");
}
return 0;
}
//方法4
#include
#include
int main()
{
int ch = 0;
//存放元音字母的数组
char vowel[] = "AaEeIiOoUu";
//输入
while((ch=getchar()) != EOF)
{
//判断
//strchr 是用来判断 ch 是否在字符串vowel出现
//如果出现了,返回vowel的字符串中的地址
//如果没出现,返回NULL
if(strchr(vowel, ch))
{
printf("Vowel\n");
}
else
{
printf("Consonant\n");
}
getchar();//去除每个字符后的\n
}
return 0;
}
解析:
参考代码:
//代码一
#include
int main()
{
int ch = 0;
while((ch=getchar()) != EOF)
{
//判断字母
//if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
if(isalpha(ch))
{
printf("%c is an alphabet.\n", ch);
}
else
{
printf("%c is not an alphabet.\n", ch);
}
getchar();//清理掉\n
}
return 0;
}
//代码二
#include
int main()
{
int ch = 0;
while((ch=getchar()) != EOF)
{
//判断字母
if(isalpha(ch))
{
printf("%c is an alphabet.\n", ch);
}
else
{
printf("%c is not an alphabet.\n", ch);
}
getchar();//清理掉\n
}
return 0;
}
解析:
参考代码:
//代码一
#include
#include
int main()
{
int ch = 0;
//多组输入
while((ch=getchar()) != EOF)
{
if(islower(ch))
{
printf("%c\n", toupper(ch));
}
else if(isupper(ch))
{
printf("%c\n", tolower(ch));
}
getchar();//处理'\n'
}
return 0;
}
//代码二
#include
int main()
{
int ch = 0;
//多组输入
while(~scanf("%c\n", &ch)
{
if(ch>='A' && ch<='Z')
{
printf("%c\n", ch+32);
}
else if(ch >='a' && ch<='z')
{
printf("%c\n", ch-32);
}
}
return 0;
}
参考代码:
#include
int main()
{
int t = 0;
while(scanf("%d", &t) !=EOF)
{
if(t>0)
printf("%d\n", 1);
else if(t == 0)
printf("%.1f\n", 0.5f);
else
printf("%d\n", 0);
}
return 0;
}
解析:
参考代码:
#include
int main()
{
int a = 0;
int b = 0;
int c = 0;
//当scanf读取结束或者失败的时候,就会返回EOF
while(scanf("%d %d %d", &a, &b, &c) != EOF)
//while(~scanf("%d %d %d", &a, &b, &c))
{
//判断是否为三角形
if(a+b>c && b+c>a && c+a>b)
{
if(a==b && b==c)//是三角形
{//等边
printf("Equilateral triangle!\n");
}
else if((a==b &&a!=c) || (a==c && a!=b) || (b==c &&b!=a))
{//等腰
printf("Isosceles triangle!\n");
}
else
{//普通
printf("Ordinary triangle!\n");
}
}
else
printf("Not a triangle!\n");
}
return 0;
}