当前位置:网站首页>Computer experiment in C language of Wuhan University of science and Technology (Part I, Part II and part III)
Computer experiment in C language of Wuhan University of science and Technology (Part I, Part II and part III)
2022-04-21 14:45:00 【A monster that doesn't like fish】
Preface : The code is for reference only , The school compiler is too low-level to fine tune
Probably not BUG When I finished writing the code, I was already VS2019 I've run on it
When reading the code, be sure to understand the comments
I wish you a happy study ! Happy everyday !
experiment 1 VC++6.0 Development environment and sequential structure programming
1. Enter a Celsius temperature , Output Fahrenheit temperature required . The formula for converting Celsius temperature to Fahrenheit temperature is f=9/5*c+32.
#include <stdio.h>
int main()
{
double c = 0;
double f = 0;
scanf("%lf", &c);
f = 9.0 / 5 * c + 32;// It can't be used here 9/5 The compiler will default to integer division
printf("%lf", f);
return 0;
}
2. Enter two integers , Output their sum 、 The square of sum 、 The sum of the squares .
#include <stdio.h>
int main()
{
int a = 0;
int b = 0;
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;// First define variables and several containers for storing and
scanf("%d", &a);
scanf("%d", &b);
sum1 = a + b;
sum2 = (a + b) * (a + b);
sum3 = a * a + b * b;
printf("%d\n",sum1);
printf("%d\n", sum2);
printf("%d\n", sum3);
return 0;
}
3、 2006 year , A football team won 98 game , lost 55 game . Use this information to write a C Program , Calculate and show the team in 2006 Percentage of wins during the year .
#include <stdio.h>
int main()
{
double win = 98;
double lose = 55;
double total = 0;
total = win + lose;
double rate = win / total;
printf("%lf%%", rate*100);
return 0;
}
experiment 2 Choose structural programming
1. Enter several characters , Count the number of numeric characters respectively 、 The number of English letters .
#include <stdio.h>
int main()
{
int i = 0;
int arr[100] = {
0};
int count = 0;
int num1 = 0;
int num2 = 0;
printf(" Please enter the content :\n");
while((arr[i]=getchar())!='\n')// Space as end sign
{
i++;
count++;
}
// Enter the string
for(i=0; i<count; i++)
{
if(arr[i]<='z' && arr[i]>='A')
{
num1++;
}
if(arr[i]>='0'&&arr[i]<='9')
{
num2++;
}
}
printf(" This string of characters has %d Letters , Yes %d A digital .\n",num1,num2);
return 0;
}
2. Programming to solve ax2+bx+c=0 The root of the , among a、b、c Input by keyboard .
#include <stdio.h>
#include<math.h>
int main()
{
double a = 0;
double b = 0;
double c = 0;
double d1 = 0;
double d2 = 0;
printf(" Please enter three coefficients :");
scanf("%lf %lf %lf", & a, &b, &c);
if (a == 0)
{
printf(" The root of the equation is :%lf", -b / c);
}
else if (a != 0 && ( b * b - 4 * a * c ) >0)
{
d1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
d2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
printf(" The root of the equation is :%lf and %lf", d1, d2);
}
else
{
printf(" This system of equations has no solution !");
}
return 0;
}
3. Know the profit of the project received by the employees of a company in a month profit( Integers ) The relationship with profit commission is as follows ( The unit of measurement is yuan ):
profit≤1000 No commission
1000 < profit≤2000 Royalty 10 %
2000 < profit≤5000 Royalty 15 %
5000 < profit≤10000 Royalty 20 %
10000 < profit Royalty 25 %
Enter the number of profits , Calculate the profit commission .
#include <stdio.h>
int main()
{
double commission = 0;
int profit = 0;
printf(" Please enter the number of profits :");
scanf("%d", &profit);
if (profit <= 1000)
{
profit = 0;
}
else if (1000 < profit && profit <= 2000)
{
commission = profit * 0.1;
}
else if (2000 < profit && profit <= 5000)
{
commission = profit * 0.15 ;
}
else if (5000 < profit && profit <= 10000)
{
commission = profit * 0.2;
}
else if (10000 < profit)
{
commission = profit * 0.25 ;
}
printf(" Put forward to be %lf", commission);
return 0;
}
experiment 3 Cyclic structure programming ( One )
⒈ Make a program , Please Fibonacci (Fibonacci) Sequence :1,1,2,3,5,8,………. Please output before 20 term . The sequence satisfies the relation : Fn = Fn - 1 + Fn - 2.
#include <stdio.h>
int main()
{
int arr[20] = {
1,1,2,0, };
int i = 0;
printf("%d ,%d ",arr[0],arr[1]);
for (i = 3; i <= 19; i++)
{
arr[i] = arr[i - 1] + arr[i - 2];
printf("%d ", arr[i]);
}
return 0;
}
⒉ Enter two positive integers m and n, Find the greatest common divisor and the least common multiple .
#include <stdio.h>
int main()
{
int m = 0;
int n = 0;
int max = 0;// This is used to store the larger of the two numbers
int i = 0;
scanf("%d %d", &m, &n);
if (m > n)
{
max = m;
}
else
{
max = n;
}
for (i = max; i > 2; i--)
{
if (m % i == 0 && n % i == 0)
{
printf(" The greatest common divisor is %d\n", i);
break;
}
}
for (i = max;; max++)
{
if (max % m == 0 && max % n == 0)
{
printf(" The least common multiple is %d\n", max);
break;
}
}
return 0;
}
⒊ seek Sn=a+aa+aaa+……+aa…a It's worth , Its a Chinese stands for 1 To 9 A number in . for example :a representative 2, Then ask 2 + 22 + 222 + 2222 + 22222( here n = 5),a and n Input by keyboard .
#include<stdio.h>
#include<math.h>
int main()
{
int n = 0;
int num = 0;
int a[10] = {
0};
int sum = 0;
while (scanf("%d", &n) != EOF)
{
for (int i = 0; i < n; i++)
{
num = num + 2 * pow(10, i);
a[i] = num;
}
for (int i = 0; i < n; i++)
{
sum = sum + a[i];
}
printf("%d\n", sum);
sum = 0;// The next set of data is updated to the initial state , namely sum by 0,Num=0
Num = 0;
}
return 0;
}
⒋ Enter a positive integer from the keyboard n, Calculate the sum of the bits of the number and output . for example , The number of inputs is 5246, The calculation :5 + 2 + 4 + 6 = 17 And the output .
#include <stdio.h>
int main()
{
int n = 0;
int ret = 0;
int sum = 0;
scanf("%d", &n);
while (n > 0)
{
ret = n % 10;
sum += ret;
n = n / 10;
}
printf("%d", sum);
return 0;
}
版权声明
本文为[A monster that doesn't like fish]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211440592124.html
边栏推荐
- Insect 1602
- Experience and guidance of seniors preparing for the postgraduate entrance examination of Applied Psychology in Northeast Normal University in 2023
- word输入公式快捷键
- [cloud based co creation] Huawei cloud database - basic knowledge
- 使用Go语言通过RestfulAPI完成学生信息管理系统
- Mysql database (3)
- Mysql数据库(2)
- Dapr 远程调试之 Nocalhost
- Mysql8.0以上重置初始密码的方法
- 五个拿来就能用的炫酷登录页面
猜你喜欢
随机推荐
武汉科技大学C语言上机实验题(第一第二第三部分)
Druid database link problem
Mysql database (2)
脚本操作ES
索信达获金融街资本1亿元投资
如何申请免费SSL证书?宝塔面板SSL证书安装部署完整教程
阿里月薪15k的测试岗,面试原来这么简单
Worm PWM
Analysis on development mode of bounty hunter automatic Trading Robot
IK word splitter
Insect 1602
Verse协议:一个优化NFT流动性的奇妙构思
Lightgbm topic 5: data consolidation of pyspark table data processing
.Net C# Newtonsoft.Json JsonSerializerSettings配置
架构实战毕业总结
2023年大连理工大学资源与环境考研上岸前辈备考经验指导
Golang Gorm框架初始化的优美解决方案
海外云服务器备份和恢复的6种最佳做法
C language preprocessing problem
The conversion between RDD and dataframe in pyspark is realized by RDD processing dataframe: data segmentation and other functions









