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


边栏推荐
- 2021-01-03
- LeetCode - 706 设计哈希映射(设计) *
- 2021-10-27
- yocto 技术分享第四期:自定义增加软件包支持
- Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*
- yocto 技術分享第四期:自定義增加軟件包支持
- Opencv image rotation
- LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
- Adaptiveavgpool1d internal implementation
- 01仿B站项目业务架构
猜你喜欢
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
El table X-axis direction (horizontal) scroll bar slides to the right by default
LeetCode - 673. Number of longest increasing subsequences
CV learning notes - feature extraction
CV learning notes - clustering
My notes on intelligent charging pile development (II): overview of system hardware circuit design
LeetCode - 919. 完全二叉树插入器 (数组)
Leetcode 300 longest ascending subsequence
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
LeetCode - 1670 設計前中後隊列(設計 - 兩個雙端隊列)
随机推荐
2020-08-23
Working mode of 80C51 Serial Port
2.Elment Ui 日期选择器 格式化问题
(1) 什么是Lambda表达式
Mobile phones are a kind of MCU, but the hardware it uses is not 51 chip
CV learning notes - scale invariant feature transformation (SIFT)
Stm32f407 key interrupt
. DLL and Differences between lib files
MySQL root user needs sudo login
Interruption system of 51 single chip microcomputer
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
Dictionary tree prefix tree trie
Swing transformer details-2
STM32 general timer 1s delay to realize LED flashing
On the problem of reference assignment to reference
Circular queue related design and implementation reference 1
Swing transformer details-1
Yocto Technology Sharing Phase 4: Custom add package support
My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
Basic use and actual combat sharing of crash tool