7-1 实验1_1_求两数的和与差 (100 point(s))
输入两个整数,求这两个整数的和与差并输出。和为两数相加,差为第一个输入的数减去第二个输入的数。
输入格式:
为用空格分隔的两个整数,并且这两个整数以及它们的和、差均不会超过int类型的存储范围。
输出格式:
只有一行,假设输入了1与2这两个整数,那么输出是“The sum is 3 and the difference is -1.”
输入样例:
1 2
输出样例:
The sum is 3 and the difference is -1.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,sum,def;
scanf("%d %d",&a,&b);
sum=a+b;
def=a-b;
printf("The sum is %d and the difference is %d.\n",sum,def);
system("pause");
return 0;
}
7-2 实验1_2_基本类型数据的输入和输出 (100 point(s))
编写一程序,按照顺序分别输入某学生的性别、年龄和身高(以米为单位),你的任务是将三者按照规定的格式输出。性别要用一个字符型(char型)变量存储,年龄要用一个整型(int 型)变量存储,身高要用一个单精度浮点型(float 型)变量存储。
输入格式:
为三行,第一行为一个字符‘M’或‘F’代表性别;第二行为一个整数,代表年龄;最后一行为一个浮点数,代表身高。测试用例保证输入合法。
输出格式:
只有一行,形如:“The sex is M, the age is 18, and the height is 1.660000.”。
输入样例:
M
18
1.66
输出样例:
The sex is M, the age is 18, and the height is 1.660000.