printf()函数练习
1.#include<stdio.h>
main()
{
printf("hello world");
}
RUN:
2.#include<stdio.h>
main()
{
printf("%d,%o,%x",11,11,11);
}
RUN:
3. #include<stdio.h>
main()
{
printf("\"hel\tlo\b\"\n\?");
}
RUN:
4. #include<stdio.h>
main()
{
int a=2,b=3;
printf("a+b=%d",a+b);
}
RUN:
5. #include<stdio.h>
#define N 5.6
main()
{
int a=2;
float s;
s=a/3+N/3+(a+N)/2;
printf("s=%f",s);
}
RUN:
6. #include<stdio.h>
main()
{
int a=2;
float b=3.2;
a=a+b;
b=a+b;
printf("a=%d,b=%f",a,b);
}
RUN:
7. 下列程序运行与TC3.0环境中
#include<stdio.h>
main()
{
int a =32765,b=7,c,d;
float e;
c=a+b;
d=c%b;
e=b/d;
printf("c=%d,d=%d,e=%f",c,d,e);
}
RUN:
8. #include<stdio.h>
main()
{
int a=5,b=6;
printf("a=%d,b=%d\n",a,b);
a+=b;
b=a-b;
a-=b;
printf("a=%d,b=%d\n",a,b);
}
RUN:
9. #include<stdio.h>
main()
{
int a=5,b=20,c=5;
c+=b/a;
a-=b*c;
b=a/c;
printf("a=%d,b=%d,c=%d\n",a,b,c);
}
RUN:
10. #include<stdio.h>
main()
{
int a,b;
a+=a-=(b=4)*(a=3);
b%=(a-a%7);
printf("a=%d,b=%d\n",a,b);
}
RUN:
11.main()
{
long y=-43456;
printf(“y=%-8ld\n”,y);
printf(“y=%-08ld\n”,y);
printf(“y=%08ld\n”,y);
printf(“y=%+8ld\n”,y);
}
关于printf函数正确的是RUN:
12.main()
{
int y=2456;
printf(“y=%3o\n”,y);
printf(“y=%8o\n”,y);
}
RUN:
13.main()
{
long y=23456;
printf(“y=%3x\n”,y);
printf(“y=%8x\n”,y);
}
RUN:
14.#include <stdio.h>
main()
{float a=123.456; double b=8765.4567;
printf(“(1) %f\n”,a);
printf(“(2) %14.3f\n”,a);
printf(“(3) %6.4f\n”,a);
printf(“(4) %lf\n”,b);
printf(“(5) %14.3lf\n”,b);
printf(“(6) %8.4lf\n”,b);
printf(“(7) %.4f\n”,b);
}
RUN:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论