当前位置:网站首页>Based on if nesting and function call
Based on if nesting and function call
2022-07-25 22:11:00 【Xiaotang blog】
subject : Get three numbers on the keyboard , Print out the maximum value , Minimum and sub maximum
Ideas : It can be encapsulated and called based on functions if Nesting of
1. Please enter three numbers (printf、scanf)
2. Define a function k
3.k Compare with these three numbers
4. Finally, function encapsulation and ternary operation are done
Source code
#include <stdio.h>
void printfwelcome()
{
printf("=====================================\n");
printf("\n");
printf("\t Welcome to my program !\n");
printf("\n");
printf("=====================================\n");
}
int getTwodata1(int x,int y)
{
return x>y?x:y;
}
int getTwodata2(int x,int y)
{
return x<y?x:y;
}
int getmaxdata(int a,int b,int c)
{
int max;
max=getTwodata1(a,b);
max=getTwodata1(max,c);
return max;
}
int getmindata(int a,int b,int c)
{
int min;
min=getTwodata2(a,b);
min=getTwodata2(min,c);
return min;
}
int main()
{
int data1;
int data2;
int data3;
int TheMax;
int TheMin;
int k;
printfwelcome();
printf(" Please enter three numbers :\n");
scanf("%d%d%d",&data1,&data2,&data3);
if(data1>data2)
{
k=data1;
data1=data2;
data2=k;
}
if(data1>data3)
{
k=data1;
data1=data3;
data3=k;
}
if(data2>data3)
{
k=data2;
data2=data3;
data3=k;
}
TheMax=getmaxdata(data1,data2,data3);
TheMin=getmindata(data1,data2,data3);
printf(" The number you entered is :%d %d %d \n",data1,data2,data3);
printf("\t\n");
printf(" The second largest number is :%d\n",data2);
printf(" The maximum number is max=%d, The minimum number is min=%d\n",TheMax,TheMin);
printf(" Enter three numbers , The order from large to small is :%d>%d>%d\n",TheMax,data2,TheMin);
printf("done!");
return 0;
}
Running results
D:\C Language \code\ Chapter five functions >a.exe
=====================================
Welcome to my program !
=====================================
Please enter three numbers :
999
23
99
The number you entered is :23 99 999
The second largest number is :99
The maximum number is max=999, The minimum number is min=23
Enter three numbers , From small to large, the order is :999>99>23
done!
边栏推荐
- 五种分配方式是否会产生内部碎片、外部碎片
- Solutions to the failure of win key in ikbc keyboard
- What is class loading? Class loading process?
- 在腾讯干软件测试3年,7月无情被辞,想给划水的兄弟提个醒...
- 核电站在席卷欧洲的热浪中努力保持安全工作
- How many bytes does Boolean occupy?
- 开户就可以购买收益在百分之六以上的理财产品了吗
- C语言左值和右值说明[通俗易懂]
- [fan Tan] in detail: lower control, upward management, upward drawing cake.
- The automation testing post spent 20K recruiting, but in the end, there was no suitable one. Both fresh students are better than them
猜你喜欢

【汇编语言01】基础知识

ansible+Crontab批部署巡检

Redis基础2(笔记)

Victoriametrics single node of kubernetes

8000 word super detailed custom structure type

『SignalR』.NET使用 SignalR 进行实时通信初体验

如何实现一个App应用程序,限制用户时间使用?

2day

Imitation Tiktok homepage interface

After 2 years of functional testing, I feel like I can't do anything. Where should I go in 2022?
随机推荐
What is class loading? Class loading process?
jenkins+SVN配置
Why does redis choose single thread?
Sofa weekly | open source person - Niu Xuewei, QA this week, contributor this week
Ts:typera code fragment indentation display exception (resolved) -2022.7.24
Jenkins+svn configuration
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
C语言游戏 双缓存解决闪屏问题 详细总结[通俗易懂]
Detailed summary of C language game dual cache to solve the flash screen problem [easy to understand]
internship:普通常用的工具类编写
Don't know mock test yet? An article to familiarize you with mock
如何将一个域名解析到多个IP地址?
Jmeter--- set proxy recording request
JSP novice
How to implement an app application to limit users' time use?
微信发卡小程序源码-自动发卡小程序源码-带流量主功能
ansible+Crontab批部署巡检
Summary of function test points of wechat sending circle of friends on mobile terminal
Playwright tutorial (I) suitable for Xiaobai
Basic knowledge in the project