第三章练习
p2t2
#include<stdio.h>
int main()
{
int ch =0;
printf("please input a value of ascii:");
scanf("%d",&ch);
getchar();
printf("the number is:%c\n",(char)ch);
}
p3t4
#include<stdio.h>
int main()
{
float a = 0.0;
printf("enter a float number :");
scanf("%f",&a);
getchar();
printf("fixed-point notation:%f\n", a);
printf("exponential notation:%e\n", a);
printf("p notation:%a\n", a);
}
p3t8
#include<stdio.h>
#define CUPS_PER_PINT (2)
#define OUNCES_PER_CUP (8)
#define BIG_SPOONS_PER_OUNCE (2)
#define TEA_SPIINS_PER_BIG_SPOON (3)
int main()
{
float cups = 0;
float pints = 0;
float ounces = 0;
float big_spoons = 0;
float tea_spoons = 0;
printf("How many cups of tea do you want:");
scanf("%f", &cups);
getchar();
pints = cups / CUPS_PER_PINT;
ounces = cups * OUNCES_PER_CUP;
big_spoons = ounces * BIG_SPOONS_PER_OUNCE;
tea_spoons = big_spoons * TEA_SPIINS_PER_BIG_SPOON;
printf("pints:%f, cups:%f, ounces:%f, big_spoons:%f, tea_spoons:%f\n", pints, cups, ounces, big_spoons, tea_spoons);
return 0;
}