printf()函数练习
1.#include<stdio.h>
main()
{
printf("good\bboy");
}
2.#include<stdio.h>
main()
{int a=17;
printf("%d,%o,%x",a,a,a);
}
3. #include<stdio.h>
main()
{
printf("this \t is\’a\’");
}
4. #include<stdio.h>
main()
{
int a=2,b=3;
int c;
c=a/b;
printf("a+b=%d",c);
}
0
5. #include<stdio.h>
main()
{int x=10;
printf("%4d,%-7d\n",x,x);
double y=3.1415926;
printf("%8.6lf",y);
}
6. #include<stdio.h>
main()
{
int a;
float b=4;
a=0;
a=a>b?a:b;
b=a+b;
printf("a=%d,b=%f",a,b);
}
0
7. #include<stdio.h>
main()
{char a,b,c,x;
x=(a='A',b='b',c=a+1);
printf("c=%d,d=%c,e=%c",a,b,x);
}
8. #include<stdio.h>
main()
{
int a=3,b=2;
a=a>b?++a:b++;
printf("a=%d,b=%d\n",a,b);
a+=b;
b=a-b;
a-=b;
函数printf printf("a=%d,b=%d\n",a,b);
}
9. #include<stdio.h>
main()
{char c='A';
char b;
b=(c>='A'&&c<='Z')?c+32:c;
printf("%c,%c\n",c,b);
}
10. #include<stdio.h>
main()
{
int a=2,b=7;
a+=a-=4;
b%=(a-a%2);
printf("a=%d,b=%d\n",a,b);
}
11#include<stdio.h>
main()
{
long y=-277;
printf("y=%-6ld\n",y);
printf("y=%-06ld\n",y);
printf("y=%06ld\n",y);
printf("y=%+6ld\n",y);
}
12. #include<stdio.h>
main()
{
int a=3,b=2,c=1;
printf("%d\n",a>b?a++:b++);
printf("%d\n",a>b?c++:b++);
b<c?printf("%d",c):printf("%d",b); }
13#include<stdio.h>
main()
{
float y=2345.66;
printf("y=%3.3f\n",y);
printf("y=%8.1f\n",y);
}
14. #include<stdio.h>
main()
{
int x=4;
float y=9.878;
printf("x=%.1f,y=%d",(float)x,(int)y);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论