3-1 略
3-2
#include <stdio.h>
int main(void)
{
printf("please enter a value.\n");
int value; //注意小写的a ASCll码值为97,大写A的ASCLl为65
scanf("%d",&value); //往后依次减一
printf("%c\n",value);
return 0;
}
3-3
#include <stdio.h>
int main(void)
{
printf("\a");
printf("startled by the sudden sound,sally shouted\n");
printf("by the great pumpkin,what was thet!\n");
return 0;
}
3-4
#include <stdio.h>
int main()
{
float a;
scanf("%f",&a);
printf("%f\n",a);
printf("%e\n",a);
printf("%x\n",a);
return 0 ;
}
3-5
#include <stdio.h>
int main(void)
{
int age;
scanf("%d",&age);
double second = 3.156e7; //一开始用的float,不行,范围不够
printf("%g\n",age * second);
return 0;
}
3-6
#include <stdio.h>
#define MASS_PER_MOLE 3.0e-23
#define MASS_PER_QUART 950
int main(void)
{
double quart;
printf("Please enter a quart for water: ");
scanf("%lf", &quart);
printf("%g quart water have %e water molecules.\n", quart, quart * MASS_PER_QUART / MASS_PER_MOLE);
return 0;
}
3-7
#include <stdio.h>
#define CM_PER_INCH 2.54
int main(void)
{
double inch;
printf("Please enter your height(inch): ");
scanf("%lf", &inch);
printf("Your height is %g cm.\n", inch * CM_PER_INCH);
return 0;
}
3-8
#include <stdio.h>
#define PINT_PER_CUP 2
#define CUP_PER_OUNCE 8
#define OUNCE_PER_BIGSPOON 2
#define BIGSPOON_PER_TEASPOON 3
int main(void)
{
double pint, ounce, cup;
double bigspoon, teaspoon;
printf("Please you enter a number of cups: ");
scanf("%lf", &cup);
pint = cup / PINT_PER_CUP;
ounce = cup * CUP_PER_OUNCE;
bigspoon = ounce * OUNCE_PER_BIGSPOON;
teaspoon = bigspoon * BIGSPOON_PER_TEASPOON;
printf("Here are some ways to show %g cups:\n", cup);
printf("Pint: %g\n", pint);
printf("Ounce: %g\n", ounce);
printf("Bigspoon: %g\n", bigspoon);
printf("Teaspoon: %g\n", teaspoon);
return 0;
}