scanf 函数最主要的用法是:scanf("输入控制符", 输入参数);函数原型:int scanf(const char * restrict format,...);函数 scanf() 是从标准输入流stdin (标准输入设备,一般指向键盘)中读内容的通用子程序,可以说明的格式读入多个字符,并保存在对应地址的变量中。
1、字符型char:%c;2、整形int:%d;3、单精度float:%f;4、双精度double:%lf;例:include<stdio.h> defineC"CProgramming"intmain(void){ inta=12345;floatb=5.12345678;chare,d,f;scanf("%c%c%c",&e,&d,&f);printf("intis:%d\n",a);printf("floatis:%f\n",b);printf("...
scanf("%f,%f,%f",&a,&b,&h)scanf是格式化输入,输入的时候必须严格按照“”内的样子!include
include <stdio.h>int main(int argc, char** argv){float a, b, c;printf("please input the number:\n");scanf("%f,%f,%f", &a, &b, &c);//输入三个变量,以英文逗号分隔float max = a;if (max < b){max = b;}if (max < c){max = c;}printf("the maximum: %f\n"...
看scanf("%f,%d",&a,&b); 对于double型a肯定要要用%lf严格格式处理了,c语言的scanf功能虽强大,但要求你规范输入,当然对于printf中的%f,float、double型参数都可输出include<stdio.h>include <math.h>double power(float x,int n){int nn=fabs(n);double m=1.0;while(nn--)m*=x;...
&是取地址,scanf读取变量的时候,参数需要的是变量的实际内存地址,了解C语言指针的概念后就会明白,地址就是指针,指向变量的数据内容。不过一般%s是不会用&取地址的,因为字符串类型本身就是指针,不需要再进一步取地址。
include <stdio.h>include <math.h>void main(){float a,b,c,d,q,p,x1,x2;printf("请输入一元二次方程系数abc");scanf("%f%f%f",&a,&b,&c);q=sqrt(b*b-4*a*c);p=-b/(2*a);d=q/(2*a);x1 =p-d;x2 =p+d;printf("x1=%f,x2=%f\n",x1,x2);}可以了,弄半天...
include <stdio.h> void main(){ int a,b,c;printf("请输入a和b的值:");scanf("%d %d", &a, &b);c = a * b;printf("a*b = %d\n",c);}
三个if语句大括号里面的语句功能都一样,都是把两个数互换。下面的示例代码输出三个浮点数由小到大的排列。如只需输出最大,输出C即可。include<stdio.h> main(){ float a,b,c,t;scanf("%f%f%f",&a,&b,&c);if (a>b){ t=a;a=b;b=t;} if (a>c){ t=a;a=c;c=t;} if (...
include main(){ float a,b;scanf("%f%5.1f",&a,&b);/ 请不要把printf函数和scanf函数的控制字符混淆 / printf("a=%f,b=%f\n",a,b);getch();} 我做的修改 include main(){ float a,b;scanf("%f%f",&a,&b);/ 请不要把printf函数和scanf函数的控制字符混淆 / printf("a=%f,...