实验七

来源:互联网 发布:全问号 乱码 java 编辑:程序博客网 时间:2024/04/29 07:12

LAP7_1


/*
    计算1-2+3-4+…+99-100。
*/
#include <iostream>#include <conio.h>using namespace std;int main(){    int i, j = 1;    int sum = 0;    for(i=1; i<=100; i++)    {        sum = sum + i*j;        j = j * (-1);    }    cout<<"The sum of 1-2+3-4+…+99-100 is :"<<sum<<endl;    _getch();    return 0;}

LAP7_2


/*
输入一个整数,将各位数字反转后输出。
*/

#include<iostream>#include<conio.h>using namespace std;int main(){    int a = 0;    int result = 0;    cout<<"Please input the integer number :"<<endl;    cin>>a;    while(a)    {        result = a % 10 +result*10;        a /= 10;    }    cout<<"The result of reverse :"<<result<<endl;    _getch();    return 0;}