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

边栏推荐
- CV learning notes - deep learning
- Timer and counter of 51 single chip microcomputer
- CV learning notes convolutional neural network
- The new series of MCU also continues the two advantages of STM32 product family: low voltage and energy saving
- LeetCode - 673. Number of longest increasing subsequences
- LeetCode - 5 最长回文子串
- Connect Alibaba cloud servers in the form of key pairs
- Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
- My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
- STM32 general timer 1s delay to realize LED flashing
猜你喜欢

Mobile phones are a kind of MCU, but the hardware it uses is not 51 chip

Working mode of 80C51 Serial Port

Leetcode bit operation

Serial communication based on 51 single chip microcomputer

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

Leetcode 300 longest ascending subsequence

QT self drawing button with bubbles

Notes on C language learning of migrant workers majoring in electronic information engineering

el-table X轴方向(横向)滚动条默认滑到右边

yocto 技术分享第四期:自定义增加软件包支持
随机推荐
(1) 什么是Lambda表达式
2021-11-11 standard thread library
Leetcode - 933 number of recent requests
getopt_ Typical use of long function
LeetCode - 895 最大频率栈(设计- 哈希表+优先队列 哈希表 + 栈) *
Dynamic layout management
Pymssql controls SQL for Chinese queries
LeetCode - 933 最近的请求次数
Opencv notes 17 template matching
Windows下MySQL的安装和删除
01 business structure of imitation station B project
STM32 running lantern experiment - library function version
ADS simulation design of class AB RF power amplifier
openEuler kernel 技术分享 - 第1期 - kdump 基本原理、使用及案例介绍
Stm32 NVIC interrupt priority management
2312. Selling wood blocks | things about the interviewer and crazy Zhang San (leetcode, with mind map + all solutions)
MySQL root user needs sudo login
2021-01-03
The data read by pandas is saved to the MySQL database
Development of intelligent charging pile (I): overview of the overall design of the system