当前位置:网站首页>[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;
}

边栏推荐
- Tensorflow2.0 save model
- LeetCode - 919. Full binary tree inserter (array)
- Problems encountered when MySQL saves CSV files
- 20220603数学:Pow(x,n)
- LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
- Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
- Application of 51 single chip microcomputer timer
- LeetCode - 705 设计哈希集合(设计)
- 20220610其他:任务调度器
- getopt_ Typical use of long function
猜你喜欢

LeetCode - 1670 设计前中后队列(设计 - 两个双端队列)

yocto 技術分享第四期:自定義增加軟件包支持

Leetcode - 1670 conception de la file d'attente avant, moyenne et arrière (conception - deux files d'attente à double extrémité)

CV learning notes ransca & image similarity comparison hash

2021-10-28

CV learning notes - feature extraction

2021-10-27

ADS simulation design of class AB RF power amplifier

Leetcode - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*

LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*
随机推荐
STM32 general timer output PWM control steering gear
CV learning notes - edge extraction
Leetcode - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*
Application of external interrupts
Installation and removal of MySQL under Windows
Leetcode 300 最长上升子序列
2. Elment UI date selector formatting problem
LeetCode - 919. Full binary tree inserter (array)
Opencv histogram equalization
Pymssql controls SQL for Chinese queries
LeetCode - 673. 最长递增子序列的个数
Discrete-event system
is_ power_ of_ 2 judge whether it is a multiple of 2
My 4G smart charging pile gateway design and development related articles
Gif image analysis drawing RGB to YUV table lookup method to reduce CPU occupancy
Cases of OpenCV image enhancement
CV learning notes - deep learning
openCV+dlib實現給蒙娜麗莎換臉
Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*
2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)