当前位置:网站首页>C语言基础练习题目
C语言基础练习题目
2022-07-27 13:16:00 【南风fahaxiki】
题目一:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
#include<stdio.h>
int main()
{
int i,j,k,l=0;
printf("题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?\n");
for(i=1;i<5;i++) { // 以下为三重循环
for(j=1;j<5;j++) {
for(k=1;k<5;k++){
if(i!=k&&k!=j&&i!=j){
printf("%d,%d,%d\n",i,j,k);
l+=1;
}
}
}
}
printf("一共有%d行",l);
}题目二:求100-999中所有的水仙花数,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。
#include <stdio.h>
int main(){
int a,i,j,k;
for(a=100;a<1000;a++){
i = a/100%10;
j = a/10%10;
k = a%10;
if(k*k*k+j*j*j+i*i*i==a){
printf("%d\n",a);
}
}
}题目三:输入某年某月某日,判断截止到这一天这一年一共过了多少天?
#include <stdio.h>
int main()
{
int year,month,day,sum;
printf("请输入年月日,格式为2022,3,28\n");
scanf("%d,%d,%d",&year,&month,&day);
switch(month){
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("月份错误");break;
}
sum=sum+day;
/*检测是否为闰月*/
if(year%400==0 || year%4==0 && year%100!=0){
if(month > 2){
sum = sum + 1;
}
}
printf("%d年截至到%d月%d日一共过了%d天",year,month,day,sum);
return 0;
}题目四:编程计算100 至 999 之间有多少个数,其各位数字之和是 5 。
#include <stdio.h>
int main(){
/*i为百位,j为10位,k为个位*/
int i,j,k,num;
for (num=100;num<999;num++){
i = num/100;
j = num /10 % 10;
k = num % 10;
if(i+j+k == 5){
printf("%d\n",num);
}
}
printf("结束");
return 0;
}
然后今天就讲到这里啦,大家记得点赞收藏,分享转发,关注小哥哥哦! 最后,如果你想学或者正在学C/C++编程,可以加入小编的编程学习C/C++企鹅圈
边栏推荐
- 解气!哈工大被禁用MATLAB后,国产工业软件霸气回击
- Lighting 5g in the lighthouse factory, Ningde era is the first to explore the way made in China
- Redis
- Mining enterprise association based on Enterprise Knowledge Map
- 达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人
- [luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging
- 592. Fraction addition and subtraction
- [note] logistic regression
- Chinese character style transfer --- antagonistic discriminative domain adaptation (L1)
- 2022牛客多校二_ E I
猜你喜欢

Slam overview Reading Note 4: a survey on deep learning for localization and mapping: towards the age of spatial 2020

【论文精读】Grounded Language-Image Pre-training(GLIP)

windows10 安装Sql Server 2019

Flexible and easy to use WYSIWYG visual report

基于企业知识图谱的企业关联关系挖掘

机场云商sign解析

GoPro access - control and preview GoPro according to GoPro official document /demo

Unity3D学习笔记10——纹理数组

在Oracle VirtualBox中导入Kali Linux官方制作的虚拟机
![[training day3] section [greed] [two points]](/img/4f/4130a1ade0ac0003adeddca780ff14.png)
[training day3] section [greed] [two points]
随机推荐
592. Fraction addition and subtraction
watch VS watchEffect
[training day4] anticipating [expected DP]
spark job 使用log4j appender 追加日志到本地文件或者mysql
Arduino+ze08-ch2o formaldehyde module, output formaldehyde content
Windows10 installing SQL Server 2019
[luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging
How to view revenue and expenditure by bookkeeping software
"Game engine light in light out" 4.1 unity shader and OpenGL shader
Negative ring
Schematic diagram of C measuring tool
Document translation__ Tvreg V2: variational imaging method for denoising, deconvolution, repair and segmentation (part)
Docker实践经验:Docker 上部署 mysql8 主从复制
c语言分层理解(c语言数组)
【多线程的相关内容】
poj3461 Oulipo【KMP】
[training day4] card game [greed]
Spark job uses log4j appender to append logs to local files or mysql
开源版思源怎么私有部署
One of yolox improvements: add CBAM, Se, ECA attention mechanism