省略第一第二题,迟一点在另一篇博文里补上答案。
这次会在题目前面写上一些难点考点。
Btw这一章对新手不友好啊,看完了一遍感觉似懂非懂,之后继续学的时候需要再回过头来学一次。
第三题:
*printf(“”)里如果还需要有双引号,需要用"来表示。
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
printf("\a Startled by the sudden sound, Sally shouted,\n\"By the Great Pumpkin, what was that!\"");
return 0;
}
//在printf里面要打印用到双引号的话,要在双引号前面加\
第四题:
注意不同的输出格式,小数%f,指数%e
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
float value;
printf("Enter a floating-point value: ");
scanf("%f",&value);
printf("fixed-point notation: %f",value);
printf("\n");
printf("exponential notation: %e",value);
return 0;
}
第五题:
int main(int argc, char *argv[]) {
int age;
double second;
printf("Please enter your age: ");
scanf("%d",&age);
second=age*3.156e7;
printf("You have been in the world for %f seconds!",second);
return 0;
}
第六题
注意要预测数据输出的格式,如果是指数的话要用%e
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
double number;
double answer;
printf("Please enter your katos: ");
scanf("%f",&number);
answer=950*number/3.0e-23;
printf("You got %e atoms in total!",answer); //注意此处%e!
return 0;
}
第七题:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
float inch;
float centimeter;
printf("Please enter your height in inches: ");
scanf("%f",&inch);
centimeter=inch*2.54;
printf("Your height in centimeters is: %f",centimeter);
return 0;
}
第八题
这道题懒得查体积单位的英文名了,直接用了拼音/拼音加s
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
float cup,pintuo,pansi,tangshao,chashao;
printf("Please enter the amount of cups: ");
scanf("%f",&cup);
pintuo=cup/2;
pansi=cup*8;
tangshao=pansi*2;
chashao=tangshao*3;
printf("%f cups equals to %f pintuos, %f pansis, %f tangshaos, %f chashaos.",cup,pintuo,pansi,tangshao,chashao);
return 0;
}