数据类型:
ASCII码:
转义字符:
数据类型 占位符列表 转义字符
char 1(byte)=8(bit) %c和%hhd
unsigned char %c和%hhu
%c对应字符身份,%hhd和%hhu对应数字身份
short 2(byte) %hd
unsigned short
%hu
long 4(byte) %ld
unsigned long %lu
int 4(byte)=32(bit) %d
unsigned int %u
float 4(byte) %f和%g 注意:保存小数点后两位:%.2lf
double 8(byte) %lf和%lg 0.000000
题目:给出书本的单价,给出书本的数量,计算输出总价;
#include<stdio.h>
#include<math.h>
#include<conio.h>//getch()
#include<windows.h>
struct booknumber{
int mathnumber;
int englishnumber;
};
struct booknumber bn;
main()
{
double math = 13.3;
double english = 20.1;
double sum;//总价
int a ;
printf("%d",sizeof(a));
printf("请输入购买书的数量!任意键继续\n");
getch();
printf("请输入购买英语书的数量:");
scanf("%d",&bn.englishnumber);
// printf("购买英语书的数量为%d:\n",bn.englishnumber);
printf("请输入购买数学书的数量:");
scanf("%d",&bn.mathnumber);
// printf("购买数学书的数量为%d:\n",bn.mathnumber);
sum = (english * bn.englishnumber)+(math * bn.mathnumber);
printf("购买书的总价为%lf:\n",sum);
system("pause");//
return 0;
}
题目:输出如下
2//输入行数2
22 33 33 66 66 66 //显示两行,固定的间距(转义字符设定)
44 55 11 25 47 58
#include<stdio.h>
#include<stdlib.h>//
#include<conio.h>//
#include<windows.h>
main()
{
int i,j;//行、列
int m,n;
//char a[i][100];
printf("请输入你需要显示的行:");
scanf("%d",&i);
printf("请输入你需要显示的例:");
scanf("%d",&j);
for(m=0;m<i;m++)
{
printf("\n");
for(n=0;n<j;n++)
{
printf("*\t");
}
}
printf("\n");
system("pause");
}