#include <stdio.h>
#include <ctype.h>
int main(void)
{
int high = 100;
int low = 1;
int guess = (high + low) / 2;
#include <stdio.h>
int imin(int, int);
int main(void)
{
int evil1, evil2;
printf("Enter a pair of integers (q to quit):\\n");
变量和常量的使用示例。
#include <stdio.h>
#define GRAMS_PER_POUND 454
const int TARGET_YEAR = 2010;
反斜杠字符(\\)是printf()函数中的特殊字符。要显示反斜杠,必须使用此转义序列。
要在输出的文本中插入引号,请使用转义序列:\\"。
#include <stdio.h>
int main()
要在输出的文本中插入单引号,请使用转义序列\\'。
#include <stdio.h>
int main()
代码
格式化说明
%a
十六进制输出,格式为0xh.hhhhp + d(仅限C99)。
%A
十六进制输出,格式为0Xh.hhhhP + d(仅限C99)。
可以分别使用%o和%x以八进制或十六进制格式显示整数。对于大写十六进制格式,请使用%X格式说明符; 对于小写,请使用%x,如下所示:
#include <stdio.h>
int sample;
int main(void)
{
printf("%p", &sample);
return 0;
}
在返回对printf()的调用之后,此变量将保存输出的字符数,直到遇到%n的代码点。
%与格式代码之间的整数设置最小字段宽度。填充确保它达到某个最小长度。如果该值超过该最小值,它仍将完整打印。默认填充是使用空格完成的。如果要填充0,请在字段宽度限定符之前放置0。
以下程序为1到19之间的数字生成一个正方和立方表:
#include <stdio.h>
int main(void)
精度修饰符在最小字段宽度修饰符之后设置。它由一个句点后跟一个整数组成。其确切含义取决于应用它的数据类型。
默认情况下,所有输出都是右对齐的。要左对齐,请在%后面直接放置一个减号。例如,%-10.2f左对齐一个浮点数,在10个字符的字段中有两个小数位。
使用#前面的g,G,f,E或e修饰符确保即使没有小数位也会有小数点。
在#前面加上x或X修饰符会导致十六进制数用0x前缀打印。
printf()使用以下格式:
printf("format_string"[,var[,...]]);
printf()转换字符
转换字符
序列
快捷方式或等同于
\\a
发出哔哔声
\\b
退格(将光标向后移动,不擦除)
\\f
换页(弹出打印机页面)
#include <stdio.h>
int main()
{
printf("for %d years.\\n",65-19);
printf("for %d years.\\n",969-65);
#include <stdio.h>
int main()
{
char menuitem[] = "Slimy Orange Stuff \\"Icky Woka Gu\\"";
#include <stdio.h>
int main()
{
printf("Now, the speed limit here is %i.\\n",55);
printf("But I clocked you doin' %i.\\n",55+15);
#include <stdio.h>
#define SPEED 55
int main()
{
printf("Now, the speed limit here is %i.\\n",SPEED);
#include <stdio.h>
int main(void)
{
int ten = 10;
int two = 2;//
printf("Doing it right: ");
编写一个程序,创建一个名为toes的整数变量,设置它的值为10。计算两次脚趾的数量和脚趾的平方数。打印所有三个值,识别它们。
#include <stdio.h>
void one_three(void);
void two(void);
int main(void)
{
printf("starting now:\\n");
#include <stdio.h>
int main(void)
{
float weight;
float value;/* platinum equivalent*/
printf("Please enter your weight in pounds: ");
#include <stdio.h>
#define QUIT3
int get_menu_choice( void )
{
int selection = 0;
do{
printf( "\\n1 - Beep" );
#include <stdio.h>
int main( void ){
int a = 12, b = 10, c = 510;
float f = 11.05, g = 25.51, h = -10.1;
#include <stdio.h>
int main (void)
{
charc = 'A';
chars[] = "abcdefghijklmnopqrstuvwxyz";
#include <stdio.h>
int main (){
float d = 6.5;
float half, square, cube;
half = d / 2;
square = d * d;
#include <stdio.h>
int main (void)
{
printf ("Testing...");
printf ("....1");