第二周的课程学完了,但是习题网站已关闭了,在第三周课程中 PAT解释中有三道编程相关的题目
交作业啦!坚持go go go
注:int型 printf和scanf中为%d,
double型 printf为%f,scanf为%lf
编程题:
2-0 整数四则运算 计算两个正整数A,B的和 差 商 积 并输出结果
#include<stdio.h>
int main()
{
int a , b;
printf("please input two numbers\n");
scanf("%d %d", &a , &b);
printf(" a + b = %d\n", a+b);
printf(" a - b = %d\n", a-b);
printf(" a * b = %d\n", a*b);
printf(" a / b = %d\n", a/b);
return 0;
}
测试结果为
(课件中没找到2.1题)
2-2 当前时间是几点?
第一个时间表示当前时间,第二个数字表示流逝的分钟数,计算当前时间(当天内)
#include<stdio.h>
int main()
{
int a , b , c, d;
printf("please input the time \n");
scanf("%d", &a);
printf("please input the past minutes\n");
scanf("%d",&b);
c = (a / 100 * 60 + a % 100 + b) / 60;
d = (a / 100 * 60 + a % 100 + b) % 60;
printf("now the time is %d%d\n", c , d);
return 0;
}
测试结果为
2.3 逆序三位数
将一个三位数进行逆序
#include<stdio.h>
int main()
{
int a , b ;
printf("please input a munber between 100~999\n");
scanf("%d", &a);
b = a/100 + a%100%10*100 + a%100/10*10;
printf("reverse number is %d", b );
return 0;
}
测试结果为