当前位置:网站首页>Exercise analysis summary
Exercise analysis summary
2022-06-23 01:42:00 【'Dream_】
If you will It's better to start than to give up . Roman.
May we all have our own goals and are making unremitting efforts for them .
-----------------------------------------------------------------------
1. Find the maximum of the three numbers .
//1. Find the maximum of the three numbers .
// Two by two The biggest one is max in
#include<stdio.h>
int main()
{
// Method 1 : Utilization cycle
/*int i = 0;
int num[3] = { 0 };
printf(" Please enter any three integers :\n");
for (i = 0; i < 3; i++)
{
scanf("%d", &num[i]);
}
int max = num[0];
for (i = 1; i < 3; i++)
{
if (max < num[i])
{
max = num[i];
}
}
printf("max = %d\n", max);*/
// Method 2 : Direct input
int a = 0;
int b = 0;
int c = 0;
printf(" Please enter any three integers :\n");
scanf("%d %d %d", &a, &b, &c);
int max = 0;
max = (a > b) ? (a) : (b);
max = (max > c) ? (max) : (c);
printf("max=%d\n", max);
return 0;
}
********************************************
2. The three integers are arranged in descending order .
//2. The three integers are arranged in descending order .
// Given a particular order :a b c( From big to small )
// Three pairwise comparisons
#include<stdio.h>
int main()
{
/*int a = 0;
int b = 0;
int c = 0;
int tmp = 0;
printf(" Please enter any three integers :\n");
scanf("%d %d %d", &a, &b, &c);
if (a < b)
{
tmp = a;
a = b;
b = tmp;
}
if (a < c)
{
tmp = a;
a = c;
c = tmp;
}
if (b < c)
{
tmp = b;
b = c;
c = tmp;
}
printf(" From large to small :%d %d %d\n", a, b, c);*/
return 0;
}******************************************
3、 Find the greatest common divisor of two numbers .
//3、 Find the greatest common divisor of two numbers .
// division
#include<stdio.h>
int main()
{
int a = 0;
int b = 0;
printf(" Please enter any two integers :\n");
scanf("%d %d", &a, &b);
while (a % b != 0)
{
int c = a % b;
a = b;
b = c;
}
printf(" greatest common divisor :%d\n", b);
return 0;
}************************************************
4、 Find the least common multiple of two numbers .
//4、 Find the least common multiple of two numbers .
// a*b/ greatest common divisor
#include<stdio.h>
int main()
{
int a = 0;
int b = 0;
printf(" Please enter any two integers :\n");
scanf("%d %d", &a, &b);
int mul = a * b;
while (a % b != 0)
{
int c = a % b;
a = b;
b = c;
}
printf(" Minimum common multiple :%d\n", (mul / b));
return 0;
}****************************************
5、 Judge 100-200 The prime number in .
//5、 Judge 100-200 The prime number in .
// Mark Optimize sqrt(i)
#include<stdio.h>
#include<math.h>//sqrt The header file
int main()
{
int i = 0;
printf("100-200 The prime number in :\n");
for (i = 101; i <= 200; i+=2)// Even numbers can't be prime numbers
{
int flag = 1;// Pay attention to the position : Update each cycle
int j = 0;
for (j = 2; j <= sqrt(i); j++)// Pay attention to the scope : At least one of the two multipliers is less than or equal to the square root value
{
if (0 == i % j)
{
flag = 0;
break;
}
}
if (flag == 1)
{
printf("%d ", i);
}
}
return 0;
}*******************************************************
6、 seek 1/1-1/2+1/3-1/4....+1/99-1/100 Value .
//6、 seek 1/1-1/2+1/3-1/4....+1/99-1/100 Value .
// Be careful -1 Write method of
#include<stdio.h>
#include<math.h>
int main()
{
int i = 0;
int j = 1;
double sum = 0.00;
for (i = 1; i <= 100; i++)
{
//sum += (double)((1.0 / i) * j);
//j = -j;//-1 Input mode 1
//-1 Input mode 2
sum += (double)((pow(-1.0, (double)i + 1)) * (1.0 / i));
}
printf("1/1-1/2+1/3-1/4....+1/99-1/100 Value :%lf\n",sum);
return 0;
}--------------------------------------------------------------------------------------- Add
- #include #define Not a keyword , It's preprocessing instructions
- char Classified as an integer ,char Is the storage used ASCII code , and ASCII Code is an integer
- When calculating “abcdef” For length strlen, The length calculation only includes ‘\0’ Number of all previous characters
---------------- All a person's anger comes from the pain of his incompetence .---------------------
边栏推荐
- Express framework installation and start service
- Population standard deviation and sample standard deviation
- Overview of visual object detection technology based on deep learning
- Debian10 LVM logical volumes
- Js--- SVG to png
- Day367: valid complete square
- [cmake command notes]find_ path
- [template] KMP
- Using WordPress to create a MySQL based education website (learning notes 2) (technical notes 1) xampp error1045 solution
- Thread local storage understanding
猜你喜欢

Installing MySQL for Linux

Module 8 job

JS - single sign on

The devil cold rice # 099 the devil said to travel to the West; The nature of the boss; Answer the midlife crisis again; Specialty selection

SQL programming task05 job -sql advanced processing

Using WordPress to create a MySQL based education website (learning notes 2) (technical notes 1) xampp error1045 solution

Express framework installation and start service

Binary String

Nuxt - auto generate dynamic route bug

Local deployment and problem solving of IIS in ArcGIS JS 4.23
随机推荐
Similar to attention NLP
MySQL -- how to access the database of a computer in the same LAN (prenatal education level teaching)
时间复杂度
Wechat mobile terminal development - account login authorization
Module 8 job
11. function template, class template, implementation vector sequence container, and space adapter
ERROR { err: YAMLException: end of the stream or a document separator is expected at line 6, colum
JS to read the picture of the clipboard
Constexpr keyword
Population standard deviation and sample standard deviation
Char[], char *, conversion between strings
Byte order: big endian vs little endian
MySQL basic command statement
What aspects of language and database knowledge are needed to build a web Kanban!
Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;
You can also do NLP (classification)
How to type Redux actions and Redux reducers in TypeScript?
[Title Fine brushing] 2023 Hesai FPGA
Summary of the first week of winter vacation
Extend your kubernetes API using the aggregation API