导航菜单
首页 >  » 正文

计算机编程题目 计算机编程题

计算机编程题目



#include"iostream.h"
double fac(int n){//n!
if(n<2){
return 1;
}else{
return n*fac(n-1);
}
}
double sum(int n){//an=1/n!前n项和
if(n<1){
return 0;
}else{
return sum(n-1) 1/fac(n);
}
}
void main(void){
cout<<"1 1/2! 1/3! 1/4! 1/5!="<}

计算机编程题

#include
using namespace std;
class complex{
public:
double sb;
double xb;
complex(){sb=0,xb=0;};
complex(double k,double x);
void display();
complex operator (complex &p);
complex operator -(complex &y);
complex operator *(complex &p);
complex operator /(complex &p);
};
complex::complex(double k,double x):sb(k),xb(x){}
complex complex::operator (complex &p)
{
complex c;
c.sb=sb p.sb;
c.xb=xb p.xb;
return c;
}
complex complex::operator -(complex &y)
{
complex c;
c.sb=sb-y.sb;
c.xb=xb-y.xb;
return c;
}
complex complex::operator*(complex &p)
{
complex c;
c.sb=sb*p.sb;
c.xb=xb*p.xb;
return c;
}
complex complex::operator /(complex &p)
{
complex c;
c.sb=sb / p.sb;
c.xb=xb / p.xb;
return c;
}
void complex::display()
{cout <<"(" <int main()
{
complex t1(7,8),t2(2,9),t3;
t3=t1 t2;
cout <<"t1 t2";
t3.display();
t3=t1-t2;
cout<<"t1-t2";
t3.display();
t3=t1*t2;
cout<<"t1*t2";
t3.display();
t3=t1/t2;
cout<<"t1/t2";
t3.display();
return 0;
}

c语言程序设计试题


#include
int main()
{
int n,deci;
   double pay,hour,avg;
   printf("Please input your pay and hour:");
   scanf("%lf%lf",&pay,&hour);
avg = pay/hour;
n = (int)avg;
deci =(avg-n)*100;
printf("Your average hourly pay rate is %d dollars and %d cents. ",n,deci);
  return 0;
}

C语言编程考试题

#include #include #include void main() { int i,j; int a[10]; srand(time(NULL));//随机种子 for (i=0;i<=9;i ) { a[i]=rand()0;/生成随机数,处理了随机数从0----99 } for (i=9;i>=0;i--) { printf("%d ",a[i]);//逆序输出 } for (i=0;i<=9;i ) for (j=i;j<=9;j )//冒泡排序 { if (a[j]>a[i]) { int tmp; tmp=a[j]; a[j]=a[i]; a[i]=tmp; } } printf(" 从小到大排序如下: "); for (i=9;i>=0;i--) { printf("%d ",a[i]); } }

Java编程题

原发布者:shensuiliunian

浙江工业大学计算机学院《Java程序设计》编程题——赵小敏自编2011一、程序设计基础1、用for语句实现下面的程序ForDemo.java:从10~100以内能被2整数但不能被3整除的整数,要求每行按10个数(数与数之间有一个空格间隔)的形式对其输出。程序的源文件名为PrintPrimeNumber.java。类名为PrintPrimeNumber。2、编写一个getY(doublet)方法,返回值按下列函数计算:t2-10≤t<1t3-2·t-21≤t<3y=t2-t·sint3≤t<5t 15≤t<7t-1其它3、编写一个java应用程序,从键盘输入x,利用下列台劳公式计算cos(x)的值,并输出(要求精确到0.000001)。台劳公式为:cos(x)=1-x2/2! x4/4!-x6/6! x8/8!-„„4、编写Java独立应用程序,先产生1个随机数n(要求0