1.
#include <stdio.h>
int main(void) {
int input;
printf("Enter a value of char int ASCII:");
scanf("%d",&input);
printf("You input value is %d,and char is %c\n",input,input);
getchar();
return 0;
}
2.
#include <stdio.h>
int main(void) {
char ch = '\a';
printf("%c",ch);
printf("Starled by the sudden sound,Sally shouted, \n");
printf("\"By the Great Pumpkin,what was that!\"\n");
getchar();
return 0;
}
3.
#include <stdio.h>
int main(void) {
float input;
printf("Enter a floating-point value:");
scanf("%f",&input);
printf("fixed-point notation: %f \n",input);
printf("exponential notation: %f \n",input);
printf("p notation: %a \n",input);
getchar();
return 0;
}
4.
#include <stdio.h>
#define SEC_PER_YEAR 3.156e7
int main(void) {
float second,year;
printf("Enter how many years old you are:");
scanf("%f",&year);
second = year*SEC_PER_YEAR;
printf("You are: %1f years old. \n",year);
printf("And you are %e seconds old,too. \n",second);
getchar();
return 0;
}
5.
#include <stdio.h>
#define MASS_PER_MOLE 3.0e-23
#define MASS_PER_QUART 950
int main(void) {
float quart,quantity;
printf("Enter how many quart:");
scanf("%f",&quart);
quantity = quart*MASS_PER_QUART/MASS_PER_MOLE;
printf("There are %e molecule. \n",quantity);
getchar();
return 0;
}
6.
#include <stdio.h>
#define INCH_TO_CM 2.54
int main(void) {
float inch,cm;
printf("Enter the inch of your heigh:");
scanf("%f",&inch);
cm = inch*INCH_TO_CM;
printf("HI,your are %0.2f inch, or %.2f cm heigh\n",inch,cm);
getchar();
return 0;
}
7.
#include<stdio.h>
#include<stdlib.h>
#define PINT_CUP 2
#define CUP_OUNCE 8
#define OUNCE_SPOON 2
#define SPOON_TEA 3
int main(void){
float pint,cup,ounce,spoon,tea_spoon;
printf("Enter how many cup:");
scanf("%f",&cup);
pint = cup/PINT_CUP;
ounce = cup*CUP_OUNCE;
spoon = ounce*OUNCE_SPOON;
spoon = ounce*SPOON_TEA;
tea_spoon = spoon*SPOON_TEA;
printf("%.lf cup equals %.lf pint, %.lf ounce, %.lf spoon, %.lf tea_spoon.\n",cup,pint,ounce,spoon,tea_spoon);
system("pause");
return 0;
}
来源:oschina
链接:https://my.oschina.net/u/4774092/blog/4864201