2023-2024年度第二学期程序设计班期末结业测试

*
您的姓名:
*
班别:
*
1.
#include<iostream>  
using namespace std; 
int main(){
int a,b,c,d;  
cin>>a>>b;  
c=a++;
d=++b;
cout<<a<<" "<<b<<" "<<c<<" "<<d; 
return 0;  
}
输入:3 5
输出:
*
2.
看程序写结果:
#include<iostream>
using namespace std;
int main(){
int i,s;
s=0;i=0;
do{
s=s+i;
i+=2;
}while(i<=6);
cout<<s;
return 0;
}
输出:
*
3.
#include<iostream>
using namespace std;
int main(){ int i,j,k=0,s=0;
for(i=1;i<=3;i++){
 s++;
 if(i==2)break;
k+=i;
}
cout<<s<<" "<<k;
return 0;
}
输出:
*
4.
#include<iostream>
using namespace std;
int main(){ int i,j,k=0,s=0;
for(i=1;i<=3;i++){
s++;
if(i==2)continue;
k+=i;
}
cout<<s<<" "<<k;
return 0;
}
输出:
*
5.
#include<iostream>
using namespace std;
int f(int x,int &y){
    x++;
    y++;
   return x+y;
}
int main(){ 
int  a=3,b=5,c;
 c=f(a,b);
cout<<a<<" "<<b;<<" "<<c;
return 0;
}
输出: 
*
6.
#include<iostream>
using namespace std;
int f(int x,int  y){
   if(x==10)
   return y;
   f(x+1,y+x+1);
}
int main(){ 
 int c;
 c=f(1,1);
cout<<c;
return 0;
}
输出: 
7.
输入一个整数(不超过10000000),判断是否对称数,例如:6336 ,121 均为对称数,8585不是对称数.如果是对称数输出yes,否则输出no*
解法一:
#include<iostream>
using namespace std;
int main(){
int a[10]={0};
int n,i=0,j,k=0;
cin>>n;
while(n>0){
i++;
a[i]=【1】;
n=【2】;
}
for(j=1;j<i/2;j++){
if(a[j]!=【3】){k=1;break;}
}
if(k==0)cout<<"yes";else cout<<"no";
return 0;
}
【1】:【2】:【3】:
8.
【题目描述】*
在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩。
【输入】
其后有n行数据,每行包括一个学号(整数)和一个成绩(浮点数),中间用一个空格分隔。
【输出】
输出第k名学生的学号和成绩,中间用空格分隔。(注:请用%g输出成绩)
【输入样例】
5 3
90788001 67.8
90788002 90.3
90788003 61
90788004 68.4
90788005 73.9
【输出样例】
90788004 68.4
参考程序:
#include<iostream>
using namespace std;
struct node{
int id;
double score;
}stu[110],【1】;
int main()
{
int n,k;
int i,j;
cin>>n>>k;
for(i=1;i<=n;i++)
cin>>stu[i].id>>stu[i].score;
for(i=1;i<=n;i++)
for(j=【2】;j<=n;j++)
if(stu[i].score<stu[j].score)
{
temp=stu[i];
【3】;
stu[j]=temp;
}
cout<<stu[k].id<<" "<<stu[k].score;
return 0;
}
【1】:【2】:【3】:
问卷星提供技术支持
举报