C++语言问题!急!

来源:百度知道 编辑:UC知道 时间:2024/05/30 14:32:19
C++程序设计期末考试题
1. 输入10个整数,输出最大数和最小数。
2. 求1- 1/2 + 1/3 - 1/4 .....+ 1/99 - 1/100
3. 求100 至200
间的全部质数。
4.马克思手稿中的数学其:有30个人,其中有男人、女人和小孩,在一家饭馆吃饭共花了50先令;每个男人花3
先令,每个女人花2
先令,每个小孩花1
先令,问男人、女人和小孩各有几人?

用循环做!!!!!快!

#include<iostream>
#include<cmath>
#include<string>
using namespace std;

void first()
{
int i,temp,max,min;
cout<<"请输入10个整数"<<endl;
for (i=1;i<=10;++i)
{
cin>>temp;
if (i==1) max=min=temp;
else
{
if (temp>max) max=temp;
else if(temp<min) min=temp;
}
}
cout<<"最大值:"<< max <<endl;
cout<<"最小值:"<< min <<endl;
}

void second()
{
int i,sign;
double sum=0;
sign=1;
for (i=1;i<=100;++i)
{ sum += 1.0/i * sign;
sign *= -1;
}
cout<<"1- 1/2 + 1/3 - 1/4 .....+ 1/99 - 1/100 = "<<sum<<endl;
}

void third()
{
int i,j;
cout<<"100 至200 间的全部质数:"<<endl;
for (i=100; i<=200; i++)
{
for( j=2 ; j<= sqr