当前位置:网站首页>C语言经典练习题
C语言经典练习题
2022-07-24 04:18:00 【Serendipity_-】
从终端输入一个字符并输出,直到遇到’q’结束:
//从终端输入一个字符并输出,直到遇到'q'结束
#include <stdio.h>
int main(int argc, char const *argv[])
{
char i;
while (1)
{
scanf("%c", &i);
if (i == '\n')
continue;
if (i == 'q')
break;
printf("%c\n", i);
}
return 0;
}
循环输入一个5位数,判断它是不是回文数。当输入0时循环结束。
比如12321是回文数,个位与万位相同,十位与千位相同。
//循环输入一个5位数,判断它是不是回文数。当输入0时循环结束。
//即12321是回文数,个位与万位相同,十位与千位相同.
#include <stdio.h>
int main(int argc, char const *argv[])
{
int num;
while (1)
{
scanf("%d", &num);
if (num > 9999 && num < 100000)
{
int g = num % 10;
int s = num / 10 % 10;
int q = num / 1000 % 10;
int w = num / 10000;
if (g == w && s == q)
printf("%d是回文数\n", num);
else
printf("%d不是回文数\n", num);
}
else if (0 == num)
{
break;
}
else
{
printf("请输入正确的数!\n");
}
}
return 0;
}
计算数组的大小:
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a[5] = {
0};
printf("%d", sizeof(a));
return 0;
}
计算斐波那契数列前15项并逆序输出
1 1 2 3 5 8 13 21 …
从第3项开始,前两项相加等于第三项
//计算斐波那契数列前15项并逆序输出
// 1 1 2 3 5 8 13 21 ...
//从第3项开始,前两项相加等于第三项
#include <stdio.h>
int main(int argc, char const *argv[])
{
int arr[15] = {
1, 1};
for (int i = 2; i < 15; i++)
{
arr[i] = arr[i - 1] + arr[i - 2];
}
for (int i = 14; i >= 0; i--)
{
printf("%d ", arr[i]);
}
return 0;
}
输入一串字符,计算其中空格的个数
//输入一串字符,计算其中空格的个数
#include <stdio.h>
int main(int argc, char const *argv[])
{
int sum = 0;
char s[100] = "";
scanf("%[^\n]", s);
for (int i = 0; i < 100; i++)
{
if (s[i] == 32)
{
sum++;
}
}
printf("%d", sum);
return 0;
}
边栏推荐
- Therefore, the command can be transmitted to the system and confirmed by the user. For master
- Educational Codeforces Round 132 A - D
- I wrote code for openharmony, and the second phase of "code" pioneer officially opened!
- LAN SDN technology hard core insider 9 from software overlay to hardware overlay
- 训练数据量不只适用于.z据接收方对数字视
- Successfully solved: error: SRC refspec master doors not match any
- PMIX ERROR: ERROR in file gds_ ds12_ lock_ pthread.c
- dispatch_ Once's Secret
- Codeforces Round #807 (Div. 2) A - D
- svg图片颜色的修改 没有花里胡哨
猜你喜欢

From bio to realizing the function of simple multi person chat room -- IO model

Remember an online sql deadlock accident: how to avoid deadlock?

Design and implementation of data analysis platform for intelligent commerce

Three cluster schemes of redis

Particle Designer:粒子效果制作器,生成plist文件并在工程中正常使用

Experiment 6 MPEG
【望解答】数据无法正确同步了

adobe PR2022 没有开放式字幕怎么办?
![[dish of learning notes, dog learning C] Dachang written test, is that it?](/img/4c/71c7268e40f0e2a15f52083022d565.png)
[dish of learning notes, dog learning C] Dachang written test, is that it?

嵌入式系统移植【6】——uboot源码结构
随机推荐
LAN SDN hard core technology insider 20 Kang long regrets -- Specifications and restrictions (Part 1)
嵌入式系统移植【6】——uboot源码结构
Live broadcast preview | practice sharing of opengauss' autonomous operation and maintenance platform dbmind
svg图片颜色的修改 没有花里胡哨
The amount of training data is not only applicable to.Z, according to the receiver's view of the number
The list should be quickly familiar with and supported by shengteng AI processor
阿里淘系面试题:Redis 如何实现库存扣减操作和防止被超卖?
Traversal of binary tree
Oracle的并行技术
Leetcode 20 valid parentheses, 33 search rotation sort array, 88 merge two ordered arrays (nums1 length is m+n), 160 intersecting linked list, 54 spiral matrix, 415 character addition (cannot be direc
mysql服务1主2从,主主,MHA配置详细步骤
How to prevent SQL injection in PHP applications
I wrote code for openharmony, and the second phase of "code" pioneer officially opened!
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
Where is the difficulty in attracting investment in the park? Inventory of difficulties and difficulties in attracting investment in industrial parks
Remember an online sql deadlock accident: how to avoid deadlock?
Design and implementation of data analysis platform for intelligent commerce
Text attack methods open source code summary
Good performance and reliability. The parameter that initiates writing IIC co type code and is -4
MOS摄像化、数字化”包含指定(contro.熟练的