第2题
#include <stdio.h> int main(void) { int ascii; printf("Enter an ASCII code: "); scanf("%d", &ascii); printf("%d is the ASCII code for %c.\n", ascii, ascii); return 0; }第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 that!\"\n"); return 0; }第4题
#include <stdio.h> int main(void) { float num; printf("Enter a floating-point value: "); scanf("%f", &num); printf("fixed-point notation: %f\n", num); printf("exponential notation: %e\n", num); printf("p notation: %a\n", num); return 0; }第5题
#include <stdio.h> int main(void) { int age; double sec; printf("Enter your age: "); scanf("%d", &age); sec = age * 3.156e7; printf("%e seconds for %d years.\n", sec, age); return 0; }第6题
#include <stdio.h> int main(void) { float mass_mol = 3.0e-23; float mass_qt = 950; float quarts; float molecules; printf("Enter the number of quarts of water: "); scanf("%f", &quarts); molecules = quarts * mass_qt / mass_mol; printf("%f quarts of water contain %e molecules.\n", quarts, molecules); return 0; }第7题
#include <stdio.h> int main(void) { float inch_cen = 2.54; float height_inch, height_cen; printf("Enter your height (inch): "); scanf("%f", &height_inch); height_cen = height_inch * inch_cen; printf("Your height is %.2f centimeters.\n", height_cen); return 0; }第8题
#include <stdio.h> int main(void) { float pint_cup = 2; float cup_ounce = 8; float ounce_soupspoon = 2; float soupspoon_teaspoon = 3; float pints, cups, ounces, soupspoons, teaspoons; printf("Enter the number of cups: "); scanf("%f", &cups); pints = cups / pint_cup; ounces = cups * cup_ounce; soupspoons = ounces * ounce_soupspoon; teaspoons = soupspoons * soupspoon_teaspoon; printf("%g cups is equivalent to: %5g pints\n", cups, pints); printf(" or %5g ounces\n", ounces); printf(" or %5g soupspoons\n", soupspoons); printf(" or %5g teaspoons\n", teaspoons); return 0;