当前位置:网站首页>[C question set] of Ⅵ
[C question set] of Ⅵ
2022-07-03 10:11:00 【InfoQ】
write in front
Question 26 → Realization N The class of ( respectively while、for)
Question 27 → Find a specific number in an ordered array k( Two points search )
Question 28 → Use for Circular statements show 10 A random number ! Printing produces random numbers 1~100~
int ret = rand() % 10; // produce 0~9 The random number - Be careful 10 It's divisible Question 29
→
Print out the pyramid
*
***
*****
*******
*********Question 30
→
Enter two numbers , Find their greatest common divisor
Question 26 code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int i = 0;
int j = 0;
int sum = 1;
printf(" Please enter a number :");
scanf("%d", &j);
for (i = 1; i <= j; i++)
{
sum = sum * i;//sum Realization N The sum of the factorials of
}
printf("sum = %d\n", sum);
return 0;
}Question 27 code
#include<stdio.h>
int main(void)
{
int k = 7;
int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sz = sizeof(arr) / sizeof(arr[0]);
int left = 0;
int right = sz - 1;
while (left <= right)
{
int mid = (left + right) / 2;
if (arr[mid] < k)
{
left = mid + 1;
}
else if (arr[mid] > k)
{
right = mid - 1;
}
else
{
printf(" eureka , The array subscript :%d, Elements %d\n", mid,arr[mid]);
break;
}
}
if (left > right)
{
printf(" Can't find !\n");
}
return 0;
}Question 28 code
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define NUM 10
int main(void)
{
int i = 1;
srand((unsigned)time(NULL));
for (i = 1; i <= NUM; i++)
{
int ret = rand() % 100 + 1;
printf(" The first %-2d Time : Numbers -->%d\n", i, ret);
}
return 0;
}Question 29 code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int i, j, k;
int input;
printf(" Please enter a number :-->");
scanf("%d", &input);
for (i = 1; i <= input; i++)
{
// Ideas : Space & Print *
for (j = 1; j <= input - i; j++)
{
printf(" ");
}
for (k = 1; k <= 2 * i - 1; k++)
{
printf("*");
}
printf("\n");
}
return 0;
} *
***
*****
*******
*********Question 30 code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int a = 0, b = 0, t = 0;
printf(" Please enter two numbers :");
scanf("%d %d", &a, &b);
while (t = a%b)
{
a = b;
b = t;
}
// hypothesis :a = 10、b = 20
//t = 10
printf("|--------------------|\n");
printf("| The greatest common divisor of two numbers :%d|\n",b);
printf("|--------------------|\n");
return 0;
}

边栏推荐
- My notes on intelligent charging pile development (II): overview of system hardware circuit design
- LeetCode - 706 设计哈希映射(设计) *
- STM32 running lantern experiment - library function version
- Leetcode 300 longest ascending subsequence
- After clicking the Save button, you can only click it once
- 20220531数学:快乐数
- CV learning notes - feature extraction
- 20220608其他:逆波兰表达式求值
- openEuler kernel 技術分享 - 第1期 - kdump 基本原理、使用及案例介紹
- CV learning notes - reasoning and training
猜你喜欢

LeetCode - 933 最近的请求次数

openCV+dlib實現給蒙娜麗莎換臉

El table X-axis direction (horizontal) scroll bar slides to the right by default

Mise en œuvre d'OpenCV + dlib pour changer le visage de Mona Lisa

Pycharm cannot import custom package

Dictionary tree prefix tree trie

CV learning notes - deep learning

Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*

Octave instructions

For new students, if you have no contact with single-chip microcomputer, it is recommended to get started with 51 single-chip microcomputer
随机推荐
CV learning notes - feature extraction
Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
Vgg16 migration learning source code
LeetCode - 919. Full binary tree inserter (array)
Yocto Technology Sharing Phase 4: Custom add package support
QT is a method of batch modifying the style of a certain type of control after naming the control
20220602数学:Excel表列序号
Crash工具基本使用及实战分享
Tensorflow built-in evaluation
LeetCode - 5 最长回文子串
[combinatorics] combinatorial existence theorem (three combinatorial existence theorems | finite poset decomposition theorem | Ramsey theorem | existence theorem of different representative systems |
Basic use and actual combat sharing of crash tool
Leetcode-112:路径总和
Anaconda安装包 报错packagesNotFoundError: The following packages are not available from current channels:
20220606数学:分数到小数
Leetcode-513:找树的左下角值
is_ power_ of_ 2 judge whether it is a multiple of 2
Application of external interrupts
03 fastjason solves circular references
Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy