当前位置:网站首页>Select structural programming
Select structural programming
2022-06-09 18:30:00 【Minghai step】
The first 1 Turn off : Sort
Task description
Our mission : The following program is to input three integers from the keyboard and output them in descending order .
To avoid formatting errors , Please directly copy and paste the format string and prompt information given in the title into your program .
Related knowledge
Input format
The input format is as follows :
printf(" Please enter three integers :");scanf("%d%d%d",&a,&b,&c);
Output
Sorting outputs three integers from small to large .
The output format is as follows :
printf(" From small to large, the order is :%d,%d,%d",a,b,c);
Programming requirements
Please read the code on the right , Combined with relevant knowledge , stay Begin-End Code supplement within the area , Finish writing sorting applet .
Test instructions
The platform will run tests on your code , If the actual output is the same as the expected output , Customs clearance .
The sample input :
Please enter three integers :5 7 6
Sample output :
From small to large, the order is :5,6,7
Start your mission , wish you success !
#include<stdio.h>
int main()
{
int a,b,c,t;
printf(" Please enter three integers :");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
t=a;
a=b;
b=t;
}
if(a>c)
{
t=a;
a=c;
c=t;
}
if(b>c)
{
t=b;
b=c;
c=t;
}
printf(" From small to large, the order is :%d,%d,%d",a,b,c);
return 0;
}
The first 2 Turn off : Selection structure - Leap year judgment
Task description
Programming , Complete the following functions : Enter any year from the keyboard year, Judge whether the year is a leap year .
** To avoid formatting errors , Please directly copy and paste the format string and prompt information given in the title into your program .**
Related knowledge
Input
Enter any year from the keyboard .
Output
Output according to leap year , It's output "**** It's a leap year !", No output "**** It's not a leap year !", among **** Is the year currently entered .
The sample input
2000
Sample output
2000 It's a leap year !
Start your mission , wish you success !
Programming requirements
Please read the code on the right , Combined with relevant knowledge , stay Begin-End Code supplement within the area , Finish writing the selection structure - Leap year judgment applet .
Test instructions
The platform will run tests on your code , If the actual output is the same as the expected output , Customs clearance .
#include<stdio.h>
int main(void)
{
int year;
scanf("%d",&year);
if((year%4==0)&&(year%100!=0)||(year%400==0))
{
printf("%d It's a leap year !",year);
}
else
{
printf("%d It's not a leap year !",year);
}
return 0;
}The first 3 Turn off : Selection structure - Piecewise function problem
Task description
Our mission : Programming , According to the entered value , The value of the output function .
There is a function , The definition is as follows

Write a program , Input x, Output y.
Related knowledge
Input
Enter any number from the keyboard x
Output
a number y, Keep three decimal places .
Programming requirements
Please read the code on the right , Combined with relevant knowledge , stay Begin-End Code supplement within the area , Finish writing the selection structure - Piecewise function problem applet .
Test instructions
The platform will run tests on your code , If the actual output is the same as the expected output , Customs clearance .
The sample input :
14
Sample output :
181.000
#include<stdio.h>
int main(void)
{
float x,y;
scanf("%f",&x);
if(x<0&&x!=-3)
{
y=x*x+x-6;
printf("%.3f",y);
}
else if(x>=0&&x<10&&x!=2&&x!=3)
{
y=x*x-5*x+6;
printf("%.3f",y);
}
else
{
y=x*x-x-1;
printf("%.3f",y);
}
return 0;
}The first 4 Turn off : Student grade conversion
Task description
Our mission : Give a 100 point mark , Output grade is required A、B、C、D、E. 90 The above points are A80-89 It is divided into B70-79 It is divided into C60-69 It is divided into D60 It is divided into the following E, If the input data is not in 0~100 Within the scope of , Please output one line :“Score is error!”.
Related knowledge
Input
Enter a score from the keyboard , Grades can make floating point numbers .
Output
(1) If the input data is in 0 To 100 Within the scope of : A character , Indicates the grade .
(2) If the input data is not in 0~100 Within the scope of , Please output one line :“Score is error!”.
Programming requirements
Please read the code on the right , Combined with relevant knowledge , stay Begin-End Code supplement within the area , Complete the preparation of student grade conversion procedures .
Test instructions
The platform will run tests on your code , If the actual output is the same as the expected output , Customs clearance .
The sample input :
90
Sample output :
A
#include<stdio.h>
int main(void)
{
int score,grade;
scanf("%d",&grade);
if(grade>=90&&grade<=100)
{
printf("A\n");
}
if(grade>=80&&grade<90)
{
printf(" B\n");
}
if(grade>=70&&grade<80)
{
printf(" C\n");
}
if(grade>=60&&grade<70)
{
printf(" D\n");
}
if(grade<60&&grade>=0)
{
printf(" E\n");
}
if(grade>100||grade<0)
{
printf("Score is error! \n");
}
return 0;
}边栏推荐
猜你喜欢
随机推荐
crontab定时执行任务
日常2琐事^_^
微服务中使用阿里开源的TTL,优雅的实现身份信息的线程间复用
php使用unlink删除文件提示无权限
redis源码学习-04_链表
功能:多文件上传,统一提交
Go 最细节篇|pprof 统计的内存总是偏小?
Explain MySQL index
深入理解JVM和GC
Overview of GCN graph convolution neural network
Database: data field change under high-speed parallel distribution
细说腾讯如何做到直播延时降低90%以上方案
GCN图卷积神经网络概述
循环结构程序设计2
Introduction to Multivariate Statistics
Singular Value Decomposition(SVD)
解决swap file .swp already exists 问题
新股解读|位列活动内容营销行业第二位,多想云推SaaS产品打造竞争壁垒
WSL 挂载U盘
[play with Huawei cloud] Huawei cloud zero code development image compression tool









