当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- LeetCode-11:盛水最多的容器
- Computer network application layer
- 写时复制集合 —— CopyOnWriteArrayList
- Five phases of API life cycle
- RabbitMQ快速入门详解
- 14. Introduction to kubenetes
- Huawei HCIA notes
- Linked list
- Factory pattern pattern pattern (simple factory, factory method, abstract factory pattern)
- APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
猜你喜欢
When iperf is installed under centos7, the solution of make: * no targets specified and no makefile found. Stop
SQL语句的执行
平台商业化能力的另一种表现形式SAAS
上线1周,B.Protocal已有7000ETH资产!
Web上的分享(Share)API
Chapter 5 programming
Salesforce connect & external object
Concurrent linked queue: a non blocking unbounded thread safe queue
C / C + + Programming Notes: pointer! Understand pointer from memory, let you understand pointer completely
几行代码轻松实现跨系统传递 traceId,再也不用担心对不上日志了!
随机推荐
Introduction to nmon
为什么我们不使用GraphQL? - Wundergraph
Dark网站的后端为什么选择F#? - darklang
Esockettimeout solution in request in nodejs
自然语言处理(NLP)路线图 - kdnuggets
APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
Have you ever thought about why the transaction and refund have to be split into different tables
C/C++编程笔记:指针篇!从内存理解指针,让你完全搞懂指针
23 pictures, take you to the recommended system
C++邻接矩阵
Combine theory with practice to understand CORS thoroughly
Adding OpenGL form to MFC dialog
C + + adjacency matrix
Fiddler无法正常抓取谷歌等浏览器的请求_解决方案
数据库设计:范式与反范式
Salesforce connect & external object
大数据软件学习入门技巧
Octave basic syntax
Python应用场景多不多?
Introduction and application of swagger