当前位置:网站首页>20201108 programming exercise exercise 3
20201108 programming exercise exercise 3
2020-11-09 01:10:00 【Time Stiller】
2. Write a program , Ask for a prompt for ASCII Code value ( Such as ,66), Then print the input characters .
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
//wxy
int main(void)
{
int a;
printf("please input ascii number:");
scanf("%d", &a);// adopt scanf() Function to read user input , And store it a variable
printf("%c\n", a);
system("pause");
return 0;
}
3. Write a program , Give an alarm , Then print the text below :
Startled by the sudden sound, Sally shouted,
"By the Great Pumpkin, what was that!"
#include<stdio.h>
// This is the code before looking at the answer
#include<stdlib.h>
// It's not the same as the answer book, but the effect is the same /
int main(void)
{
printf("\aStartled by the sudden sound,Sally shoutde,\n");/*wxy*/
printf("\"By the Great Pumpkin,what was that!\"");/*wxy*/
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
// This is the code modified according to the answer
int main(void)
{
char ch='\a';
printf("%c",ch);
// The output characters '\a' This character indicates an alarm , But some systems may not be able to produce sound
printf("Startled by the sudden sound,Sally shoutde,\n");//wxy
printf("\"By the Great Pumpkin,what was that!\"\n");//wxy
system("pause");
return 0;
}
4. Write a program , Read a floating point number , First print it as a decimal point , And print it in exponential form . then , If the system supports , And print it as p Notation ( Hexadecimal notation ). Output... In the following format ( The actual number of index digits displayed varies by system ):
Enter a floating-point value: 64.25
fixed-point notation: 64. 250000
exponential notation: 6. 425000e+01
p notation: 0x1.01p+6
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
// watermark
#include<stdlib.h>
// watermark
int main(void)
{
float a;
printf("Enter a floating-point value:");//wxy
scanf("%f",&a);// Read user input , Store to a variable
printf("fixed-point notation:%f\n",a);// Print normal form
printf("exponential notation:%e\n",a);// Print index form
printf("p notation:%a\n",a);// Print p Counting form
system("pause");
return 0;
}
5. About a year 3.156X10^7 second . Write a program , Prompt the user to enter the age , Then the number of seconds for that age is displayed .
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
// watermark
#include<stdlib.h>
// watermark
#define SEC_PER_YEAR 3.156e7
//wxy
int main(void)
{
float year,second;// Because the values need , Age also uses floating-point data
printf("please input your age:");
scanf("%f", &year);// Read the age entered by the user
second = year * SEC_PER_YEAR;// Calculate the number of seconds for your age
printf("You are:%.1f years old.\n", year);
printf("And you are %e seconds old,too.\n", second);
system("pause");
return 0;
}
6. 1 The mass of each water molecule is about 3.0X10^-23 g .1 Quart water is about 950 g . Write a program , Prompt the user to enter the quart number of water , And show the number of water molecules .
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
// watermark
#include<stdlib.h>
// watermark
#define MASS 3.0e-23// Define the molecular mass of water
#define MASS_PER_QUART 950// Definition 1 Quarts of water mass
int main(void)
{
float quart,quantity;
printf(" Please enter the number of quarts of water :");
scanf("%f",&quart);
quantity=quart*MASS_PER_QUART/MASS;// Calculate the number of water molecules
printf(" The quart number of water is :%e\n",quantity);
system("pause");
return 0;
}
7. 1 Inches is equivalent to 2.54 centimeter . Write a program , Prompt user to enter height (/ Inch ), Then show height in centimeters .
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
// watermark
#include<stdlib.h>
// watermark
#define INTOCM 2.54
// Inch to centimeter conversion factor
int main(void)
{
float inch,cm;
printf("please input a inch:");
scanf("%f", &inch);
cm = INTOCM * inch;// Convert inches to centimeters
printf("%f inch equral to %f cm\n", inch, cm);// Print calculation results
system("pause");
return 0;
}
8. In the volume measurement system in the United States , 1 Pints are equal to 2 A cup of , 1 A cup is equal to 8 Oz. ,1 An ounce is equal to 2 Big spoon , 1 A big spoon is equal to 3 Teaspoon . Write a program , Prompt the user to enter the number of cups , And in pints 、 Oz. 、 a soup spoon 、 Teaspoons show equivalent capacity in units . Think about the program , Why floating point type is more suitable than integer type ?
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
// watermark
#include<stdlib.h>
// watermark
#define PINT_CUP 2
#define CUP_OUNCE 8
#define OUNCE_SPOON 2
#define SPOON_TEA 3
// A constant that defines the unit conversion
int main(void)
{
float pint,cup,ounce,spoon,tea;
printf(" Please input the number of cups :");//wxy
scanf("%f",&cup);
pint=cup/PINT_CUP;
ounce=cup*CUP_OUNCE;
spoon=ounce*OUNCE_SPOON;
tea=spoon*SPOON_TEA;
printf("%.1f A cup is equal to %.1f pint , be equal to %.1f Oz. , be equal to %.1f a soup spoon , be equal to %.1f Teaspoon .\n",cup,pint,ounce,spoon,tea);
system("pause");
return 0;
}
Because the cup number conversion, the finished product takes off , It may produce 0.5 Pints , At this point, the value of pints is non integer , So it's better to use floating-point data than to use integer data .
版权声明
本文为[Time Stiller]所创,转载请带上原文链接,感谢
边栏推荐
- 基于链表的有界阻塞队列 —— LinkedBlockingQueue
- 写时复制集合 —— CopyOnWriteArrayList
- Flink's datasource Trilogy 3: customization
- SaaS: another manifestation of platform commercialization capability
- CSP-S 2020 游记
- 当我们聊数据质量的时候,我们在聊些什么?
- 深度优先搜索和广度优先搜索
- Fiddler can't grab requests from browsers like Google_ Solution
- Decorator (1)
- LeetCode-11:盛水最多的容器
猜你喜欢
Five phases of API life cycle
上线1周,B.Protocal已有7000ETH资产!
Introduction to nmon
作业2020.11.7-8
Programmers should know the URI, a comprehensive understanding of the article
写时复制集合 —— CopyOnWriteArrayList
如何让脚本同时兼容Python2和Python3?
1. What does the operating system do?
移动大数据自有网站精准营销精准获客
Have you ever thought about why the transaction and refund have to be split into different tables
随机推荐
分库分表的几种常见玩法及如何解决跨库查询等问题
How to make scripts compatible with both Python 2 and python 3?
几行代码轻松实现跨系统传递 traceId,再也不用担心对不上日志了!
File queue in Bifrost (1)
写时复制集合 —— CopyOnWriteArrayList
The vowels in the inverted string of leetcode
Linked blocking queue based on linked list
为什么我们不使用GraphQL? - Wundergraph
SQL语句的执行
《MFC dialog中加入OpenGL窗体》
Flink的DataSource三部曲之三:自定义
Dark网站的后端为什么选择F#? - darklang
Execution of SQL statement
Programmers should know the URI, a comprehensive understanding of the article
How to reduce the resource consumption of istio agent through sidecar custom resource
How does pipedrive support quality publishing with 50 + deployments per day?
Nodejs中request出现ESOCKETTIMEDOUT解决方案
C++邻接矩阵
Travel notes of csp-s 2020
STS安装