当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- When iperf is installed under centos7, the solution of make: * no targets specified and no makefile found. Stop
- The vowels in the inverted string of leetcode
- 14. Introduction to kubenetes
- Combine theory with practice to understand CORS thoroughly
- A brief introduction of C code to open or close the firewall example
- Flink's datasource Trilogy 3: customization
- 常见特征金字塔网络FPN及变体
- 使用容器存储表格数据
- On buffer overflow
- Programmers should know the URI, a comprehensive understanding of the article
猜你喜欢
Depth first search and breadth first search
APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
APP 莫名崩溃,开始以为是 Header 中 name 大小写的锅,最后发现原来是容器的错!
Esockettimeout solution in request in nodejs
Several common playing methods of sub database and sub table and how to solve the problem of cross database query
How to reduce the resource consumption of istio agent through sidecar custom resource
Factory Pattern模式(简单工厂、工厂方法、抽象工厂模式)
Linked blocking queue based on linked list
Copy on write collection -- copyonwritearraylist
Database design: paradigms and anti paradigms
随机推荐
Review of API knowledge
简单介绍c#通过代码开启或关闭防火墙示例
C + + adjacency matrix
Fiddler can't grab requests from browsers like Google_ Solution
老大问我:“建表为啥还设置个自增 id ?用流水号当主键不正好么?”
自然语言处理(NLP)路线图 - kdnuggets
Introduction to nmon
使用递增计数器的线程同步工具 —— 信号量,它的原理是什么样子的?
基于链表的有界阻塞队列 —— LinkedBlockingQueue
Are there many Python application scenarios?
VIM 入门手册, (VS Code)
如何通过Sidecar自定义资源减少Istio代理资源消耗
服务器性能监控神器nmon使用介绍
Get the first cover image of video through canvas
A few lines of code can easily transfer traceid across systems, so you don't have to worry about losing the log!
Pipedrive如何在每天部署50+次的情况下支持质量发布?
Python应用场景多不多?
云计算之路-出海记-小目标:Hello World from .NET 5.0 on AWS
How to deploy pytorch lightning model to production
Factory pattern pattern pattern (simple factory, factory method, abstract factory pattern)