当前位置:网站首页>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++企鹅圈
边栏推荐
- Positive mask, negative mask, wildcard
- watch VS watchEffect
- Rtl8762dk environment construction (I)
- Golang excellent open source project summary
- uniapp的request数据请求简单封装步骤
- The difference between [x for X in list_a if not np.isnan (x)] and [x if not np.isnan (x) else none for X in list_a]
- STM32——电容触摸按键实验
- A Keypoint-based Global Association Network for Lane Detection
- Interview eight part essay · TCP protocol
- 2022 Niuke multi School II_ E I
猜你喜欢

架构——MVC的升华

基于在线问诊记录的抑郁症病患群组划分与特征分析

codeforces 1708E - DFS Trees
![[luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging](/img/e3/c2b3d45c6a0d1f7ff0b8b7bccf2106.png)
[luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging

Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading

文献翻译__基于自适应全变差L1正则化的椒盐图像去噪
![[luogu_p4820] [national training team] stack [mathematics] [physics] [harmonic progression]](/img/79/67399e6ce1908e38dc000e4b13a7ea.png)
[luogu_p4820] [national training team] stack [mathematics] [physics] [harmonic progression]

A Keypoint-based Global Association Network for Lane Detection

This points to problems, closures, and recursion

YOLOX改进之一:添加CBAM、SE、ECA注意力机制
随机推荐
va_ List usage summary
解气!哈工大被禁用MATLAB后,国产工业软件霸气回击
基于GEC6818开发板的相册
Document translation__ Tvreg V2: variational imaging method for denoising, deconvolution, repair and segmentation (part)
基于预训练模型的多标签专利分类研究
Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers
【笔记】逻辑斯蒂回归
Slam overview Reading Note 4: a survey on deep learning for localization and mapping: towards the age of spatial 2020
Charles tutorial
PROFINET simulator tutorial
[training day4] anticipating [expected DP]
SLAM综述阅读笔记六:基于图像语义的SLAM调研:移动机器人自主导航面向应用的解决方案 2020
Hard deduction SQL statement exercises, wrong question records
Travel notes from July 11 to August 1, 2022
[x for x in list_a if not np.isnan(x)]和[x if not np.isnan(x) else None for x in list_a]的区别
10 practical uses of NFT
Slam overview Reading Note 6: slam research based on image semantics: application-oriented solutions for autonomous navigation of mobile robots 2020
Weice biological IPO meeting: annual revenue of 1.26 billion Ruihong investment and Yaohe medicine are shareholders
Secondary spanning tree [template]
Docker实践经验:Docker 上部署 mysql8 主从复制