PTA-浙大版C语言程序设计(第3版)编程题
- [练习2-1 Programming in C is fun!](https://pintia.cn/problem-sets/12/problems/237)
- [练习2-3 输出倒三角图案](https://pintia.cn/problem-sets/12/problems/238)
- [练习2-4 温度转换](https://pintia.cn/problem-sets/12/problems/239)
- [练习2-6 计算物体自由下落的距离](https://pintia.cn/problem-sets/12/problems/240)
- [练习2-8 计算摄氏温度](https://pintia.cn/problem-sets/12/problems/241)
- [练习2-9 整数四则运算](https://pintia.cn/problem-sets/12/problems/242)
练习2-1 Programming in C is fun!
本题要求编写程序,输出一个短句“Programming in C is fun!”。
#include <stdio.h>
int main (void)
{
printf ("Programming in C is fun!");
return 0;
}
练习2-3 输出倒三角图案
本题要求编写程序,输出指定的由“*”组成的倒三角图案。
#include <stdio.h>
int main()
{
printf("* * * *\n * * *\n * *\n *");
}
练习2-4 温度转换
本题要求编写程序,计算华氏温度150°F对应的摄氏温度。计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型。
#include <stdio.h>
int main()
{
int fahr = 150, celsius;
celsius = 5 * (fahr - 32) / 9;
printf("fahr = 150, celsius = %d",celsius);
}
练习2-6 计算物体自由下落的距离
一个物体从100米的高空自由落下。编写程序,求它在前3秒内下落的垂直距离。设重力加速度为10米/秒2。
#include <stdio.h>
int main()
{
float height;
int s = 3;
height = 0.5*10*s*s;
printf("height = %.2f", height);
}
练习2-8 计算摄氏温度
给定一个华氏温度F,本题要求编写程序,计算对应的摄氏温度C。计算公式:C=5×(F−32)/9。题目保证输入与输出均在整型范围内。
输入格式:
输入在一行中给出一个华氏温度。
输出格式:
在一行中按照格式“Celsius = C”输出对应的摄氏温度C的整数值。
输入样例:
150
输出样例:
Celsius = 65
#include<stdio.h>
int main()
{
int C;
int f;//华氏温度
scanf("%d",&f);
C=5*(f-32)/9;
printf("Celsius = %d",C);
return 0;
}
练习2-9 整数四则运算
本题要求编写程序,计算2个正整数的和、差、积、商并输出。题目保证输入和输出全部在整型范围内。
输入格式:
输入在一行中给出2个正整数A和B。
输出格式:
在4行中按照格式“A 运算符 B = 结果”顺序输出和、差、积、商。
输入样例:
3 2
输出样例:
3 + 2 = 5
3 - 2 = 1
3 * 2 = 6
3 / 2 = 1
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("%d + %d = %d\n",a,b,a+b);
printf("%d - %d = %d\n",a,b,a-b);
printf("%d * %d = %d\n",a,b,a*b);
printf("%d / %d = %d\n",a,b,a/b);
return 0;
}