注册 登录
编程论坛 C++教室

谁能帮我做下这两个题目、、、应该很简单 但、、、我是新手

lurrass 发布于 2010-09-14 22:59, 877 次点击
1. Design a program, when you enter an integer number that is greater than 100 and less than 1000, the output result is its inverse order. For example, when you input number 563, the output result is 365.

2. According to the following formula, please calculate the value of Pai.   

Pai/4=1-1/3+1/5-1/7+...
7 回复
#2
promising2010-09-14 23:44
1.
#include<iostream.h>
int reverse(int n)
{
    int i=0;
    while(n!=0)
    {        
        i=i*10+n%10;
        n=n/10;
    }
return i;
}
void main()
{
    int n;
    cin>>n;
    if(n>100&&n<1000)
    cout<<reverse(n);
}

2.
#include<iostream.h>
void main()
{
    int i,s=0,flag=1;
    for(i=1;i<50;i=i+2)//50可换,来控制精度//
    {
        s+=flag/i;
        flag=-flag;
    }
    s*=4;
    cout<<"Pai="<<s;
}
#3
x_wangyue2010-09-15 10:38
第一题:#include <iostream>

using namespace std;

int main()
{
    int n;
    do
    {
        cout<<"please enter the intger range 100 form 1000:"<<endl;
        cin>>n;
        if(!cin)
            break;
        if(n>=1000||n<=100)
            cout<<"wrong data!"<<endl;
        else
        {
            int i,j,k;
            i=n%10;//个位
            j=n/10%10;//十位
            k=n/100;//百位
            cout<<"The number is:"<<i<<j<<k<<endl;
        }

        cin.clear();
    }while(cin);

    return 0;
}
第二题参照二楼吧,写得很简洁
#4
进球了2010-09-15 21:54
关注中
#5
风雨氵2010-09-15 21:57
顶一二楼的
#6
南国利剑2010-09-15 22:04
问题应该解决了吧。
恭喜楼主。
1