当前位置:网站首页>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;
}
边栏推荐
- The C host is always set separately for IIC. If enough, the next few bits can be set
- NFT insider 67: Barcelona Football Club launched its first NFT work, and Dubai launched the national metauniverse strategy
- Ros2 common command line tools organize ros2cli
- Chapter III query processing of PostgreSQL Guide - Insider exploration
- [untitled]
- Vscode configuration user code snippet
- 00cm non, make sure to go online with the business party once in advance, and make everything better
- May be a little useful cold knowledge
- Send data 1010_ 1. The number of bytes passed by the sender
- Insider of LAN SDN hard core technology 22 Kang long regrets -- Specifications and restrictions (Part 2)
猜你喜欢
![[development technology] spingboot database and Persistence technology, JPA, mongodb, redis](/img/fb/bb4a26699e5ec10c6881a4c95ac767.png)
[development technology] spingboot database and Persistence technology, JPA, mongodb, redis

Function application of 4G transmission module

Leetcode (Sword finger offer) - 11. Minimum number of rotation array

buu web

Avoid mistakes, common appium related problems and Solutions

阿里淘系面试题:Redis 如何实现库存扣减操作和防止被超卖?
![[novice] develop a tab component that is easy to expand by hand](/img/67/ac0a0a4861f933e447a84c24f62e79.gif)
[novice] develop a tab component that is easy to expand by hand
![Graduation thesis on enterprise production line improvement [Flexsim simulation example]](/img/83/381ef1566d5a863b709f504b46e169.png)
Graduation thesis on enterprise production line improvement [Flexsim simulation example]

Jinglianwen technology provides 3D point cloud image annotation service

Iqoo 10 series attacks originos original system to enhance mobile phone experience
随机推荐
[novice] develop a tab component that is easy to expand by hand
The value is 0. The other part includes but is not limited to the following. This question is
Configure IPv6 over IP manual tunnel using routing protocol
ARP Spoofing protection of network security
Live broadcast preview | practice sharing of opengauss' autonomous operation and maintenance platform dbmind
Codeforces Round #809 (Div. 2) A - D1
IPhone binding 163 mailbox solution
Oracle的并行技术
PMIX ERROR: ERROR in file gds_ ds12_ lock_ pthread.c
Embedded system transplantation [6] - uboot source code structure
Four characteristics of nb-iot
The second anniversary of open source, opengauss Developer Day 2022 full highlights review!
How safe is Volvo XC90? Come and have a look
Iqoo 10 series attacks originos original system to enhance mobile phone experience
Introduction to the application fields and functions of bank virtual human technology
Combinatorial number (number of prime factors of factorials, calculation of combinatorial number)
IP second experiment mGRE OSPF
er系统,在 Lin应答位时,数,成功开r Com更
Upgrade POI TL version 1.12.0 and resolve the dependency conflict between the previous version of POI (4.1.2) and easyexcel
【望解答】数据无法正确同步了