我只是根据自己的想法写的,希望有用。include<stdio.h> struct a { double l;char s[4];};int main(){ struct a m;while(scanf("%lf%s",&m.l,&m.s)!=EOF){ if(strcmp(m.s,"mm")==0){ printf("%gcm\n",m.l/10);printf("%gm\n",m.l/1000);printf("%gkm\n",m.l/...
scanf函数,与printf函数一样,都被定义在stdio.h里,因此在使用scanf函数时要加上#include<stdio.h>。它是格式输入函数,即按用户指定的格式从键盘上把数据输入到指定的变量之中,其关键字最末一个字母f即为“格式”(format)之意。[编辑本段]scanf函数的一般形式 scanf(格式控制,地址表列) int scanf(char *...
scanf (“%s”,name)是输入字符串到name字符数组,而scanf (“%c”,&name) 是输入字符到name字符数组的第一个元素。如果scanf (“%s”,&name) 会报错,因为scanf()函数中,“%s”代表对字符串格式化,需要提供的参数必须是字符数组,&name仅仅是name变量的第一个单元空间。如果scanf (“%c”,...
c语言中,输入一个字符串使用scanf("%s")和gets()在表面上看来并无太大差异,它们都承担着将字符数据输入到指定内存区域的任务。若我们定义一个名为str[30]的字符数组,通过这两者都可以进行这样的操作:scanf("%s",str);gets(str);它们都能以类似的方式输出:printf("%s",str);或者puts(str);...
include<stdio.h>#include<string.h>int main(){ char cmd[100]; do { printf("开始循环..\n"); do { printf("继续循环吗?(yes/no): "); scanf("%s",cmd); }while(strcmp(cmd,"yes") && strcmp(cmd,"no")); }while(!strcmp(cmd,"yes"));} ...
这时可以输入这样的选择:“1,2”,即求2的立方 “2,125”,即求125的立方根 “3”,退出程序*/ include<stdio.h> include<math.h> display();lifang(n);lifanggen(n);main(){ int choice,number;display();printf("请输入你的选择及整数n(用逗号来间隔):\n");scanf("%d,%d",&choice...
while( EOF != scanf("%s",cnt) ){ if( '0' == cnt[0] )break;root = 0;for( int i=0;i<strlen(cnt);++i )root += (cnt[i]-'0');while( root > 9 ){ r = root%10;root /= 10;root += r;} printf("%d\n",root);memset(cnt,0,sizeof(cnt));} return 0;...
#include<stdio.h> main(){ chara,b,c,d;inti;scanf("%d",&i);getchar();while(i--){ scanf("%c%c%c",&a,&b,&c);getchar();if(a>b){d=a;a=b;b=d;} if(a>c){d=a;a=c;c=d;} if(b>c){d=b;b=c;...
include<stdio.h> intmain(){ floatw,h,BIM;scanf("%f%f",&w,&h);w/=2;h/=100;BIM=w/h*w/h;printf("Weight:%.2fkg\nHeight:%.2fm\n",w,h);if(BIM<18.5)printf("Yourbodyistoothin.");elseif(BIM<=24)printf("Yourbodyisnormal.");else printf("Yourbodyistoofat.");re...
最后那个s是一个变量,scanf是通俗说是赋值语句,得到终端的输入对变量s初始化 相对有一个printf,这个是输出到标准外设显示。“%s”是格式化转换,这个s代表字符串,%c代表字符, %d代表整数 总体来说,这个语句是要你输入一串字符,对你设置的变量s赋值。