输入一个ASCII码值,打印输出的字符
#include<stdio.h>
int main(void)
{
int ch;
scanf("%d",&ch);
printf("%d is %c\n",ch,ch);
return 0;
}
输出"Great!"
#include<stdio.h>
int main(void)
{
printf("\"Great!\"\n");
return 0;
}
输出格式控制
#include<stdio.h>
int main(void)
{
float i;
scanf("%f",&i);
printf("输出:\n%.6f\n%e\n",i,i);
return 0;
}64.25
输出:
64.250000
6.425000e+001
#include<stdio.h>
int main(void)
{
int age;
double time;
time=3.156e7;
scanf("%d",&age);
printf("年龄%d对应的秒数为:%e\n",age,age*time);
return 0;
}18
年龄18对应的秒数为:5.680800e+008
#include<stdio.h>
int main(void)
{
int member,k;
double f;
k=950;
f=3e-23;
scanf("%d",&member);
printf("%d夸脱水分子的质量为:%d 数量为:%e\n",member,member*k,member*k/f);
return 0;
}
#include<stdio.h>
int main(void)
{
float k;
printf("输入身高(英尺):");
scanf("%f",&k);
printf("身高为:%.2f厘米\n",k*2.45);
return 0;
}输入身高(英尺):70
身高为:171.50厘米
#include<stdio.h>
#include<string.h>//提供strlen()函数的原型
#define DENSITY 62.4//定义字符常量
int main(void)
{
float weight,volume;
int size,letters;
char name[40];
printf("What's your first name?\n");
scanf("%s",name);//name前面无&
printf("%s,what's your weight in pounds?\n",name);
scanf("%f",&weight);//weight前面有&
size=sizeof(name);
letters=strlen(name);
volume=weight/DENSITY;
printf("%s,your volume is %2.2f cubic feet.\n",name,volume);
printf("your first name has %d letters,",letters);
printf("and we have %d bytes to store it.\n",size);
return 0;
}What's your first name?
ahhhhh
ahhhhh,what's your weight in pounds?
111
ahhhhh,your volume is 1.78 cubic feet.
your first name has 6 letters,and we have 40 bytes to store it.
#include<stdio.h>
#define P "I love you!"
int main(void)
{
char name[40];
printf("What's your name?\n");
scanf("%s",name);//name前面无&
printf("%s,%s\n",name,P);
return 0;
}What's your name?
baby
baby,I love you!