第七、八周作业
来源:互联网 发布:独立 知乎 编辑:程序博客网 时间:2024/05/16 14:18
作业一
例题5-3
#include<iostream>using namespace std;double circleArea(double);int main(){double area=circleArea(5.0);cout<<"area="<<area<<endl;return 0;}double circleArea(double r){double pi=3.14;double area=pi*r*r;return area;}
例题5-10
#include<iostream>using namespace std;void display(int x,float y){cout<<x<<" "<<y;return;}int main(){float a;int b;cin>>b>>a;display(b,a);return 0;}
例题5-15
#include<iostream>using namespace std;float Factorial(int n);int main(){int a;float f;cout<<"input an integer number:";cin>>a;f=Factorial(a);cout<<a<<"!="<<f<<endl;return 0;}float Factorial(int n){float fact;if(n==0)fact =1;elsefact =n*Factorial(n-1);return fact;}
作业二
第二题
#include<iostream> using namespace std; long intPower(int base,int exponent); int main() { int a,b; long int c; cout<<"请输入一个整数以及所要求的整数次幂的次数"<<endl; cin>>a>>b; c= intPower(a,b); cout<<"所求的结果为:"<<endl; cout<<a<<"的"<<b<<"次幂为:"<<c<<endl; return 0; } long intPower(int base,int exponent) { long int d=base; for(int i=1;i<exponent;i++) d *= base; return d; }
第三题
#include<iostream> using namespace std; int a; void number(int n) { int i; for(i =2;i<=n;i++) if(n%i==0) break; if(i ==n) cout<<a<<"是素数"<<endl; else cout<<a<<"不是素数"<<endl; } int main() { char b; while(1) { cout<<"请输入一个正整数"<<endl; cin>>a; number(a); cout<<"若继续请输入Y:"<<endl; cin>>b; if(b=='y'||b=='Y') { continue; cout<<endl; } else break; } return 0; }
第四题
#include<iostream> #include<math.h> using namespace std; long power(int x) { int i, t, n, k; i = 0, t = x, n = 0; while(t>0) { t = t/10; n++; } k = pow(10,n-1); while(x>0) { t = x%10; x = x/10; i += t*k; k = k/10; } return i; } int main() { int a;long i; char b; while(1) { cout<<"请输入一个正整数"<<endl; cin>>a; i=power(a); cout<<a<<"的逆转数为:"<<i<<endl; cout<<"若继续请输入Y:"<<endl; cin>>b; if(b=='y'||b=='Y') { continue; cout<<endl; } else break; } return 0; }
第五题
#include <iostream> using namespace std; void degree(int x); int main() { int a; char b; while(1) { cout<<"请输入分数:"; cin>>a; degree(a); cout<<"若继续输入请按Y;"; cin>>b; if(b == 'Y'||b == 'y') { cout<<endl; continue; } else break; } return 0; } void degree(int x) { switch(x/10) { case 6: { cout<<"该学生成绩为D"<<endl<<endl; break; } case 7: { cout<<"该学生成绩为C"<<endl<<endl; break; } case 8: { cout<<"该学生成绩为B"<<endl<<endl; break; } case 9: { cout<<"该学生成绩为A"<<endl<<endl; break; } default: cout<<"该学生成绩为不及格"<<endl<<endl; } }
第六题
#include<iostream> using namespace std; float power(int n[10]);int main(){ int a[10],k,aver; char b; while(1) { cout<<"请分别输入10个学生的分数:"<<endl; for(k=0;k<10;k++) { cout<<"a["<<k<<"]="<<endl; cin>>a[k]; } aver=power(a); cout<<"平均成绩为:"<<aver<<endl; cout<<"若继续请输入Y:"<<endl; cin>>b; if(b=='y'||b=='Y') { continue; cout<<endl; } else break; } return 0; }float power(int n[10]) { int d=0,e; for(int i=0;i<10;i++) { d+=n[i]; } e=d/10; return e; }
余下的有难度,暂时不会。。。
作业三
#include<iostream> #include<iomanip> using namespace std; int ji(int a[4][5], int b[5][3]); int main() { int a[4][5],b[5][3],c[4][3]={0},d,e; cout<<"请输入一个4行5列数组"<<endl; for(d=0;d<4;d++) { for(e=0;e<5;e++) { cin>>a[d][e]; } } cout<<"请输入一个5行3列数组"<<endl; for(d=0;d<5;d++) { for(e=0;e<3;e++) { cin>>b[d][e]; } } for(d = 0;d<4;d++) for(e = 0;e<3;e++) { c[d][e] = ji(a,b); } cout<<"A矩阵与B矩阵的积为:"<<endl; for(d = 0;d<4;d++) { for(e = 0;e<3;e++) { cout<<setw(4)<<c[d][e]; } cout<<endl; } return 0; } ji(int a[4][5], int b[5][3]) { int d,e,f,g,c[4][3]={0}; for(d=0;d<4;d++) for(e=0;e<3;e++) { for(f=0;f<5;f++) { g=a[d][e]*b[d][e]; c[d][e]=c[d][e]+g; } } return c[d][e]; }
作业四
#include <iostream> using namespace std; float factorial(int n); int main() { int n, i; char b; while(1) { float s = 0; cout<<"Please input an integer number: "; cin>>n; for(i = 1;i<=n;i++) s += factorial(i); cout<<"s"<<"["<<n<<"] = "<<s<<endl<<endl; cout<<"若继续输入请按Y:"; cin>>b; if(b == 'Y'||b == 'y') { cout<<endl; continue; } else break; } return 0; } float factorial(int n) { float fact; if(n == 0) { fact = 1; } else fact = n*factorial(n-1); return fact; }
这题不就是例题嘛。。。。
0 0
- 第七/八周作业
- 第七,八周作业
- 第七、八周作业
- 第七、八周作业(1)
- 第七、八周作业(2)
- 第七八周作业(第一部分)
- 第七次作业--八皇后问题
- 第七周作业3
- 第七周作业1
- 第七周作业2
- 第七周作业 1
- 第七周作业三
- 第七周作业
- 第七周-小作业
- 第七周作业
- 第七周作业1
- 第七周作业
- 第七周C++作业
- php网站制作(5)-类似于百度优酷等一样弹出的登陆框
- Linux 目录结构
- javascript操作html元素CSS属性
- swift学习资料初探
- java实现 阿拉伯数字转换为汉字数字 算法
- 第七、八周作业
- “棱镜”入侵手机App, 爱加密有效防窃听
- Convert Sorted Array to Binary Search Tree
- C#普通计算器与科学计算器
- 6月5号工作第二天
- 06_05_词法分析
- 注册(九)重注册
- iOS开发分辨率那点事
- android NDK *.MK文件详解