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

边栏推荐
- yocto 技术分享第四期:自定义增加软件包支持
- Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
- Working mode of 80C51 Serial Port
- CV learning notes - deep learning
- CV learning notes - reasoning and training
- 20220601数学:阶乘后的零
- Yocto Technology Sharing Phase 4: Custom add package support
- getopt_ Typical use of long function
- YOLO_ V1 summary
- Leetcode - 895 maximum frequency stack (Design - hash table + priority queue hash table + stack)*
猜你喜欢

Opencv notes 17 template matching

2021-10-28

03 fastjason solves circular references

LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)

Leetcode interview question 17.20 Continuous median (large top pile + small top pile)

SCM is now overwhelming, a wide variety, so that developers are overwhelmed

CV learning notes - scale invariant feature transformation (SIFT)

Swing transformer details-2

openEuler kernel 技術分享 - 第1期 - kdump 基本原理、使用及案例介紹

QT is a method of batch modifying the style of a certain type of control after naming the control
随机推荐
Opencv note 21 frequency domain filtering
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
yocto 技术分享第四期:自定义增加软件包支持
Connect Alibaba cloud servers in the form of key pairs
Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
It is difficult to quantify the extent to which a single-chip computer can find a job
After clicking the Save button, you can only click it once
Working mode of 80C51 Serial Port
Basic knowledge of communication interface
STM32 general timer output PWM control steering gear
Modelcheckpoint auto save model
About windows and layout
Swing transformer details-1
Yocto Technology Sharing Phase 4: Custom add package support
2312. Selling wood blocks | things about the interviewer and crazy Zhang San (leetcode, with mind map + all solutions)
Drive and control program of Dianchuan charging board for charging pile design
Opencv+dlib to change the face of Mona Lisa
Google browser plug-in recommendation
20220604数学:x的平方根
Development of intelligent charging pile (I): overview of the overall design of the system