点击这里更换您喜欢的皮肤wtboj 首页
请点击这里登入noios   首页 入门 c++讲义 入门教程视频 其他页面 入门视频 站务 公告 | 题库 记录 竞测 测试 闯关 作业 排名 团队 讨论 | 换肤 | 登入 注册  
News >>   新增功能:各团队管理员可以发布本团队作业了 ()

讨论 Discussion
 
咕咕咕咕
1.四年级 :
1. 作业点评:
题目:编程实现:
可乐自动售卖机找零钱: 输入可乐的单价和要购买的数量以及预付出的钱,要求输出找回的零钱.
样例:
输入:5 3 100
输出:85

参考程序:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;  
  cin>>a>>b>>c;  
  d=c-a*b;  
  cout<<d;  
  return 0;  
}



五年级学案:
1.课堂学习: 用递归算法实现:已知数列:1,3,5,7,9....求前n项的和
1+3+5+7+...+p=?  
样例:
输入:
3
输出:
9
参考程序:
#include<bits/stdc++.h>
using namespace std;
int n;
int f(int k,int x,int y ){//k表示当前项是第k项,x表示当前项的值,y表示前k项的值的和?
    if(k==n){cout<<y;return 0;}
    f(k+1,x+2,y+x+2);
}
int main(){
  cin>>n;
  f(1,1,1);
  return 0;  
}




六年级学案:
1.课堂学习: 用递归算法实现:已知数列:1,3,5,7,9....求前n项的和
1+3+5+7+...+p=?  
样例:
输入:
3
输出:
9
参考程序:
#include<bits/stdc++.h>
using namespace std;
int n;
int f(int k,int x,int y ){//k表示当前项是第k项,x表示当前项的值,y表示前k项的值的和?
    if(k==n){cout<<y;return 0;}
    f(k+1,x+2,y+x+2);
}
int main(){
  cin>>n;
  f(1,1,1);
  return 0;  
}

2.作业点评:
已知数列:1 2 2 3 3 3 4 4 4 4 5.....请利用递归算法输出该数列的前n项,每项间用空格分开。
样例:
输入:4
输出:1 2 2 3

参考程序:
#include<bits/stdc++.h>
using namespace std;
int n;
int f(int k,int x,int y,int z){
  if(k==n){cout<<z;return 0;}
cout<<z<<" ";
if(y==x)return f(k+1,x+1,1,z+1);
else
return f(k+1,x,y+1,z);
}
int main(){
  cin>>n;
  f(1,1,1,1);
  return 0;  
}


( )

此主题无回复显示
发布讨论主题 回复讨论主题
 Copyright wtboj © 2005-2006. www.wutuobang.date Powered by wtboj 关于 联系 帮助
 wtboj Information ---- Total Users : 1393 | Online Users / Processes : 0 / 89 | Processed Time : 47 ms | Server Time : 2026/9/10 18:06:05