当前位置:网站首页>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++企鹅圈
边栏推荐
- 进程间通信
- STM32——电容触摸按键实验
- 机场云商sign解析
- 基于RoBERTa-wwm动态融合模型的中文电子病历命名实体识别
- A Keypoint-based Global Association Network for Lane Detection
- watch VS watchEffect
- GoPro access - control and preview GoPro according to GoPro official document /demo
- 文献翻译__基于自适应全变差L1正则化的椒盐图像去噪
- Docker实践经验:Docker 上部署 mysql8 主从复制
- JS 疫情宅在家,学习不能停,七千字长文助你彻底弄懂原型与原型链
猜你喜欢

LeetCode·每日一题·592.分数加减运算·模拟

面试八股文之·TCP协议

微策生物IPO过会:年营收12.6亿 睿泓投资与耀合医药是股东

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

Rtl8762dk environment construction (I)

Alibaba's latest equity exposure: Softbank holds 23.9% and caichongxin holds 1.4%

汉字风格迁移篇---对抗性区分域适应(L1)Adversarial Discriminative Domain Adaptation

基于企业知识图谱的企业关联关系挖掘
![[luogu_p4820] [national training team] stack [mathematics] [physics] [harmonic progression]](/img/79/67399e6ce1908e38dc000e4b13a7ea.png)
[luogu_p4820] [national training team] stack [mathematics] [physics] [harmonic progression]

文献翻译__基于自适应全变差L1正则化的椒盐图像去噪
随机推荐
Shell编程规范与变量
一篇文章看懂JS执行上下文
在Oracle VirtualBox中导入Kali Linux官方制作的虚拟机
Mining enterprise association based on Enterprise Knowledge Map
[note] logistic regression
WPF visifire.charts4.6.1 tutorial with source code
GoPro access - control and preview GoPro according to GoPro official document /demo
Unity2d -- camera follow
Slam overview Reading Note 6: slam research based on image semantics: application-oriented solutions for autonomous navigation of mobile robots 2020
【STM32】EXTI
达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人
Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
JS 疫情宅在家,学习不能停,七千字长文助你彻底弄懂原型与原型链
Good architecture is evolved, not designed
PROFINET simulator tutorial
[intensive reading of papers] grounded language image pre training (glip)
What open source projects of go language are worth learning
基于招聘广告的岗位人才需求分析框架构建与实证研究
Vscode -- create template file
Golang excellent open source project summary