成绩 char cj[10];
输入字符串 scanf("%s",cj);
字符串转数值 sscanf(cj,"%f",&v);
程序如下:
#include
main()
{
char cj[10];
float v;
printf("input cj, if cj=='q' then exit\n");
while(1){
scanf("%s",cj);
if (sscanf(cj,"%f",&v)!=1) break;
if (v>=60)printf("cj is %g, pass\n",v);
else printf("cj is %g, not pass\n",v);
}
printf("good bye\n");
return 0;
}
例子:
input cj, if cj=='q' then exit
12.5
cj is 12.5, not pass
46
cj is 46, not pass
60
cj is 60, pass
86.3
cj is 86.3, pass
q
good bye