第一题
/**********************************************************/
//Function : 主函数,从键盘输入三个值
// : 并打印其和、平均数、积、最小值和最大值
//parm :
//return : void
//Author :
//date :
/**********************************************************/
#include <iostream.h>
void main()
{
int a,b,c;
int d;
cout<<"Input three different integers:";
cin>>a>>b>>c;
cout<<"Sum is "<<a + b + c<<endl; //sum
cout<<"Average is "<<(a + b + c)/3.0<<endl; //average
cout<<"Product is "<<a * b * c<<endl; //product
d = a < b ? a : b;
cout<<"Smallest is "<<(d < c ? d : c)<<endl; //min
d = a > b ? a : b;
cout<<"Largest is "<<(d > c ? d : c)<<endl; //max
}
第二题:
/**********************************************************/
//Function : main,计算0到10的平方和立方
//parm :
//comment :
//return : void
//Author :
//date :
/**********************************************************/
#include <iostream.h>
void main()
{
cout<<"number/tsquare/tcube"<<endl;
for(int i=0;i<=10;i++)
cout<<i<<"/t"<<i*i<<"/t"<<i*i*i<<endl;
}
第三题:
/**********************************************************/
//Function : main,读取五位整数并确定其是否为回文
//parm :
//comment :
//return : void
//Author :
//date :
/**********************************************************/
#include <iostream.h>
void main()
{
long num;
int a,b,d,e;
cin>>num;
a=num / 10000; //万位
b=num % 10000 / 1000; //千位
d=num % 100 / 10; //十位
e=num % 10; //个位
if(a == e && b == d )
cout<<num<<" is palindrome!"<<endl;
else
cout<<num<<" is not palindrome!"<<endl;
}
第四题:
/**********************************************************/
//Function : main,求出从1626年到2008年24美元的存款本息
//parm :
//comment :
//return : void
//Author :
//date :
/**********************************************************/
#include <iostream.h>
#include <math.h>
void main()
{
double amount,principal = 24,rate = 0.072;//amount:本息;principal:本金;rate:利率
for(int i = 1;i <= 2008 - 1626 + 1;i++) //1626到2008总共379年
amount = principal * pow(1.0 + rate, i);
cout<<amount<<endl;
}
第五题:
/**********************************************************/
//Function : main,信息加密
//parm :
//comment :
//return : void
//Author :
//date :
/**********************************************************/
#include <iostream.h>
void main()
{
int num,a,b,c,d;//信源数据,四位整数
cin>>num;
a = num / 1000;
b = num % 1000 / 100;
c = num % 100 / 10;
d = num % 10;
//以下为加密过程
a = (a + 7) % 10; //加7除10求余
b = (b + 7) % 10;
c = (c + 7) % 10;
d = (d + 7) % 10;
int temp;
temp = a; //1、3位交换
a = c;
c = temp; //2、4位交换
temp = b;
b = d;
d = temp;
cout<<a<<b<<c<<d<<endl;
//以下为解密过程
a = (a + 3) % 10; //加3除10求余
b = (b + 3) % 10;
c = (c + 3) % 10;
d = (d + 3) % 10;
temp = a; //1、3位交换
a = c;
c = temp;
temp = b; //2、4位交换
b = d;
d = temp;
cout<<a<<b<<c<<d<<endl;
}
第六题:
/**********************************************************/
//Function : main,判断一对整数中第二个整数是否为第一个整数的倍数
//parm :
//comment :
//return : void
//Author :
//date :
/**********************************************************/
#include <iostream.h>
#include <stdlib.h>
bool multiple(int x,int y) //Integer parameters function
{
if(y%x == 0)
return true;
else
return false;
}
bool multiple(int *x,int *y) //Integer pointer parameters function
{
if(*y % *x == 0)
return true;
else
return false;
}
void main()
{
int a,b;
cin>>a>>b;
if(a == 0 || b == 0)
{
cout<<"Zero unexpected!"<<endl;
exit(0);
}
if(multiple(a,b))
cout<<"True"<<endl;
else
cout<<"False"<<endl;
if(multiple(&a,&b))
cout<<"True"<<endl;
else
cout<<"False"<<endl;
}
以上程序代码仅供参考,注意编码格式及风格