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


边栏推荐
- El table X-axis direction (horizontal) scroll bar slides to the right by default
- Dictionary tree prefix tree trie
- Yocto technology sharing phase IV: customize and add software package support
- The 4G module designed by the charging pile obtains NTP time through mqtt based on 4G network
- Basic use and actual combat sharing of crash tool
- LeetCode - 673. Number of longest increasing subsequences
- LeetCode - 5 最长回文子串
- CV learning notes - feature extraction
- 使用sed替换文件夹下文件
- 20220607其他:两整数之和
猜你喜欢
openCV+dlib实现给蒙娜丽莎换脸
Leetcode bit operation
Opencv notes 17 template matching
Serial communication based on 51 single chip microcomputer
Pycharm cannot import custom package
LeetCode - 673. 最长递增子序列的个数
LeetCode - 1670 设计前中后队列(设计 - 两个双端队列)
Matplotlib drawing
CV learning notes - feature extraction
Leetcode - 933 number of recent requests
随机推荐
CV learning notes - clustering
Leetcode - 1670 conception de la file d'attente avant, moyenne et arrière (conception - deux files d'attente à double extrémité)
Leetcode 300 longest ascending subsequence
LeetCode - 673. 最长递增子序列的个数
CV learning notes convolutional neural network
On the problem of reference assignment to reference
LeetCode - 919. 完全二叉树插入器 (数组)
CV learning notes ransca & image similarity comparison hash
Application of external interrupts
Timer and counter of 51 single chip microcomputer
openCV+dlib實現給蒙娜麗莎換臉
CV learning notes - deep learning
LeetCode - 508. Sum of subtree elements with the most occurrences (traversal of binary tree)
Sending and interrupt receiving of STM32 serial port
Yocto Technology Sharing Phase 4: Custom add package support
CV learning notes alexnet
01 business structure of imitation station B project
. DLL and Differences between lib files
Swing transformer details-2
yocto 技术分享第四期:自定义增加软件包支持