当前位置:网站首页>【C 题集】of Ⅵ
【C 题集】of Ⅵ
2022-07-03 09:20:00 【InfoQ】
write in front
第二十六题→实现N的阶层(分别实现while、for)
第二十七题→在一个有序的数组中查找具体某个数字k(二分查找)
第二十八题→使用for循环语句显示10个随机数!打印产生随机数1~100~
int ret = rand() % 10; //产生0~9的随机数 - 注意10会被整除第二十九题
→
打印出金字塔
*
***
*****
*******
*********第三十题
→
输入两个数字,求它们的最大公约数
第二十六题代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int i = 0;
int j = 0;
int sum = 1;
printf("请输入数字:");
scanf("%d", &j);
for (i = 1; i <= j; i++)
{
sum = sum * i;//sum 实现N的阶乘之和
}
printf("sum = %d\n", sum);
return 0;
}第二十七题代码
#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("找到了,数组下标:%d,元素%d\n", mid,arr[mid]);
break;
}
}
if (left > right)
{
printf("找不到!\n");
}
return 0;
}第二十八题代码
#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("第%-2d次:数字-->%d\n", i, ret);
}
return 0;
}第二十九题代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int i, j, k;
int input;
printf("请输入数字:-->");
scanf("%d", &input);
for (i = 1; i <= input; i++)
{
//思路:空格 & 打印 *
for (j = 1; j <= input - i; j++)
{
printf(" ");
}
for (k = 1; k <= 2 * i - 1; k++)
{
printf("*");
}
printf("\n");
}
return 0;
} *
***
*****
*******
*********第三十题代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int a = 0, b = 0, t = 0;
printf("请输入两个数字:");
scanf("%d %d", &a, &b);
while (t = a%b)
{
a = b;
b = t;
}
//假设:a = 10、b = 20
//t = 10
printf("|--------------------|\n");
printf("|两个数的最大公约数:%d|\n",b);
printf("|--------------------|\n");
return 0;
}

边栏推荐
- Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
- The data read by pandas is saved to the MySQL database
- 2020-08-23
- Positive and negative sample division and architecture understanding in image classification and target detection
- The underlying principle of vector
- On the problem of reference assignment to reference
- el-table X轴方向(横向)滚动条默认滑到右边
- Vgg16 migration learning source code
- LeetCode - 508. Sum of subtree elements with the most occurrences (traversal of binary tree)
- [combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
猜你喜欢

The underlying principle of vector

Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn

Opencv notes 17 template matching
![[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)](/img/19/5dc152b3fadeb56de50768561ad659.jpg)
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)

Basic use and actual combat sharing of crash tool

QT is a method of batch modifying the style of a certain type of control after naming the control

2.1 Dynamic programming and case study: Jack‘s car rental

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

Windows下MySQL的安装和删除

One click generate traffic password (exaggerated advertisement title)
随机推荐
YOLO_ V1 summary
51 MCU tmod and timer configuration
CV learning notes - BP neural network training example (including detailed calculation process and formula derivation)
(2)接口中新增的方法
Do you understand automatic packing and unpacking? What is the principle?
QT is a method of batch modifying the style of a certain type of control after naming the control
STM32 running lantern experiment - library function version
My notes on intelligent charging pile development (II): overview of system hardware circuit design
The data read by pandas is saved to the MySQL database
使用密钥对的形式连接阿里云服务器
RESNET code details
CV learning notes - camera model (Euclidean transformation and affine transformation)
4G module board level control interface designed by charging pile
CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)
CV learning notes - image filter
Positive and negative sample division and architecture understanding in image classification and target detection
Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
CV learning notes convolutional neural network
LeetCode - 895 最大频率栈(设计- 哈希表+优先队列 哈希表 + 栈) *
Stm32f407 key interrupt