当前位置:网站首页>实验一
实验一
2020-11-06 22:11:00 【树大数媒201王婧】
1.缩写程序,输出以下信息: **********¥¥ ¥¥¥ This is my first C program! **********¥¥¥¥¥
#include<stdlib.h>
int main(void)
{
printf("**********¥¥\n");/*wj*/
printf("¥¥¥\n");
printf("This i my first C program!\n");
printf("**********¥¥¥¥¥\n");
system("pause");
return 0;
}```
2.输入圆柱的半径r 和高h,计算并输出其体积。
```#include<stdio.h>
#include<stdlib.h>
#define PI 3.1415926
int main(void)
{
float r, h;
float v;
printf("请输入圆柱体的半径r:");
scanf("%f", &r);
printf("请输入圆柱体的高h:");
scanf("%f", &h);
v = PI * r * r * h;
printf("圆柱体的体积v为:%f", v);
system("pause");
return 0;
}```
3.输入三个数到变量a,b,c 中,求它们的平均值。
```#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int a, b, c;/*number*/
float aver;
printf("请输入a:");
scanf("%d", &a);
printf("请输入b:");
scanf("%d", &b);
printf("请输入c:");
scanf("%d", &c);
aver = (a + b + c) / 3.0;
printf("平均值为:%f", aver);
system("pause");
return 0;
}
4.输入秒数,将它按小时.分钟.秒的形式来输出。例如输入24680,则输出6 小时51
分20 秒.
```#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int s;
int hour, minute, second;/*单位 */
printf("请输入秒数:");
scanf("%d", &s);
hour = s/3600;
minute = (s % 3600) / 60;
second = s % 60;
printf("%d秒等于%d小时%d分%d秒", s, hour, minute, second);
system("pause");
return 0;
}```
5.
(1)编写一个计算球体体积的程序,其中球体半径为10m(注意分数的写法)
(2)修改上题中的程序,使用户可以自行输入球体的半径。
```#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define PI 3.1415926
int main(void)
{
float r;/*半径*/
float v;/*体积*/
printf("请输入球体的半径r:");
scanf("%f", &r);
v = 4.00/ 3.00* PI * r * r * r;
printf("球体的体积v为:%f", v);
system("pause");
return 0;
}```
6.编写一个程序,使用printf 在屏幕上显示下面的图形:
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> int main(void) { printf(" *\n"); printf(" *\n"); printf(" *\n"); printf(" * *\n"); printf(" * *\n"); printf(" *\n"); system("pause"); return 0; }``` 7.编写一个程序,要求用户输入一个美元变量,然后显示出增加5%税率后的相应金 额,格式如下所示 Enter an amount: 100.00 With tax added:$105.00
int main(void)
{
float money;/*钱*/
float moneyWithTax;
printf("Enter an amount:");
scanf("%f", &money);
moneyWithTax = money * (1 + 0.05);
printf("With tax added:$%.2f",moneyWithTax);
system("pause");
return 0;
}```
8.(1)编程要求用户输入x 的值,然后显示如下多项式的值:
3x5+2x4-5x3-x2+7x-6
```#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float x, y;/*数*/
printf("请输入x的值:");
scanf("%f", &x);
y = 3 * x * x * x * x * x + 2 * x * x * x * x - 5 * x * x * x - x * x + 7 * x - 6;
printf("多项式3x5+2x4-5x3-x2+7x-6的值为:%f", y);
system("pause");
return 0;
}```
(2)修改上题,用如下公式对多项式求值
((((3x+2)x-5)x-1)x+7)x-6
```#include<stdio.h>
#include<stdlib.h>
int main(void)
{
float x, y;/*数*/
printf("请输入x的值:");
scanf("%f", &x);
y = ((((3 * x + 2) * x - 5) * x - 1) * x + 7) * x - 6;
printf("多项式((((3x+2)x-5)x-1)x+7)x-6的值为:%f", y);
system("pause");
return 0;
}```
9.编写一个程序,要求用户输入一个美金数量,然后显示出如何用最少的20 美元、10
美元、5 美元和1 美元来付款
Enter a dollar amount:93
$20 bills:4
$10 bills:1
$5 bills:0
$1 bills:3
(提示:将付款金额除以20,确定20 美元的数量,然后从付款金额中减去20 美元的
总金额,对其他面值的钞票重复这一操作,确保在程序中使用整数值,不要使用浮点数)
```#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int money, twenty, ten, five, one;/*12345*/
printf("Enter a dollar amount:");
scanf_s("%d", &money);
twenty = money / 20;
money = money - twenty * 20;
ten = money / 10;
money = money - ten * 10;
five = money / 5;
money = money - 5 * five;
one = money;
printf("$20 bills:%d\n", twenty);
printf("$10 bills:%d\n", ten);
printf("$5 bills:%d\n", five);
printf("$1 bills:%d\n", one);
system("pause");
return 0;
}```
版权声明
本文为[树大数媒201王婧]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4774086/blog/4706902
边栏推荐
- 嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
- What is the tensor in tensorflow?
- C and C / C + + mixed programming series 5 - GC collaboration of memory management
- Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
- Pn8162 20W PD fast charging chip, PD fast charging charger scheme
- 磁存储芯片STT-MRAM的特点
- Tron smart wallet PHP development kit [zero TRX collection]
- An article will take you to understand SVG gradient knowledge
- Open source a set of minimalist front and rear end separation project scaffold
- Python 100 cases
猜你喜欢
es创建新的索引库并拷贝旧的索引库 实践亲测有效!
磁存储芯片STT-MRAM的特点
解决 WPF 绑定集合后数据变动界面却不更新的问题
Stickinengine architecture 11 message queue
All the way, I was forced to talk about C code debugging skills and remote debugging
Introduction to the development of small game cloud
Contract trading system development | construction of smart contract trading platform
STM32F030F4P6兼容灵动微MM32F031F4P6
Pn8162 20W PD fast charging chip, PD fast charging charger scheme
超高频RFID医疗血液管理系统应用
随机推荐
Pn8162 20W PD fast charging chip, PD fast charging charger scheme
2020-08-18:介绍下MR过程?
window系统 本机查找端口号占用方法
GitHub: the foundation of the front end
解决 WPF 绑定集合后数据变动界面却不更新的问题
2020-08-24:什么是小文件?很多小文件会有什么问题?很多小文件怎么解决?(大数据)
EOS founder BM: what's the difference between UE, UBI and URI?
[forward] how to view UserData in Lua
统计项目代码行数
Why is quicksort so fast?
Introduction to the development of small game cloud
迅为iMX6开发板-设备树内核-menuconfig的使用
2020-09-09:裸写算法:两个线程轮流打印数字1-100。
Zero basis to build a web search engine of its own
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:曾文旌
The isolation level of transaction and its problems
迅为-iMX6ULL开发板上配置AP热点
Flink's datasource Trilogy: direct API
All the way, I was forced to talk about C code debugging skills and remote debugging
磁存储芯片STT-MRAM的特点