1. #include<stdio.h>int main(void){ char name[40]; char surname[40]; printf("Please input your first name:"); scanf("%s", name); printf("Please input yourlast name:"); scanf("%s", surname); printf("Hello,%s,%s", name, surname); return 0; }
2
#include<stdio.h>int main(void){ char name[40]; int width; printf("请输入姓名:"); scanf("%s", &name); width = printf("a.\"%s\"\n", name); width -= 4; printf("b.\"%20s\".\n", name); printf("c.\"%-20s\".\n", name); printf("d.\"%*s\".\n", (width + 3), name); return 0; }
3
#include<stdio.h>int main(void){ float input; printf("Enter a float number:");//wxyscanf("%f", &input); printf("a.The input is %.1f or %.1e \n", input, input); printf("\n"); printf("b.The input is %.3f or %.3e \n", input, input); return 0; }
4
#include<stdio.h>int main(void){ char name[40]; float height; printf("请输入您的身高(英寸):"); scanf("%f", &height); printf("请输入您的姓名:"); scanf("%s", name); printf("%s,you are %.3f feet tall.\n", name, height / 12.0); return 0; }
5
#include<stdio.h>int main(void){ float speed, size, time; printf("Please input the net speed(megabits per second):");//wxyscanf("%f", &speed); printf("Please input the file size(megabyte):"); scanf("%f", &size); time = size * 8 / speed; printf("At %.2f megabits per second, a file of %.2f megabytes downloads in %.2f seconds.\n", speed, size, time); return 0; }
6
#include<stdio.h>int main(void){ char name[40], surname[40]; int wname, wsurname; printf("Please input you first name:"); scanf("%s", name); printf("Please input you last name:"); scanf("%s", surname); wname = printf("%s", name); printf(" "); wsurname = printf("%s", surname); printf("\n%*d %*d\n", wname, wname, wsurname, wsurname); return 0; }
7
#include<stdio.h>int main(void){ char name[40], surname[40]; int wname, wsurname; printf("Please input you first name:"); scanf("%s", name); printf("Please input you last name:"); wname = printf("%s", name); printf(" "); wsurname = printf("%s", surname); printf("\n%d %*d\n", wname, wname, wsurname); return 0; }
8
#include<stdio.h>#define GALLON_TO_LITRE 3.785#define MILE_TO_KM 1.609int main(void){ float range, oil; printf("Pleast input the range you traveled(in mile):"); scanf("%f", &range); printf("Pleast input the oil you spend(in gallon):"); scanf("%f", &oil); printf("In USA, your oil wear is %.1f M/G\n", range / oil); printf("In Europe, your oil wear is %.1fL/100KM\n", (oil * GALLON_TO_LITRE) / (oil * MILE_TO_KM)); return 0; }