c++编程实例100例Lt
D
输入一个整数将各位征税反转后输出
#include<iostream>
using namespace std;
int main()
{
int n,right_digit,newnum=0;
cout<<"Enter the number:";
cin>>n;
cout<<"the number in revers srder is:";
do{
right_digit=n%10;
cout<<right_digit;
n/=10;
}
while (n!=0);
cout<<endl;
return 0;
}、
1~10的和
#include<iostream>
using namespace std;
int main()
{
int i=1,sum=0;
while (i<=10)
{
sum+=i;
i++;
}
cout<<"sunm="<<sum<<endl;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int i=1,sum=0;
do
{
sum+=i;
i++;
}
while (i<=10);
cout<<"sum="<<sum<<endl;
return 0;
}
工资
#include <iostream>
using namespace std;
int main()
{
long int i;
int bouns1,bouns2,bouns4,bouns6,bouns10,bouns;
scanf("%d",&i);//%ld表示这个数据的类型是long int 长整形                  //&i 表示i的地址,及输出的是i的值bouns1=100000*0.1;
bouns2=bouns1+10000090.75;
bouns4=bouns2+200000*0.5;
bouns6=bouns4+200000*0.3;
bouns10=bouns6+400000*0.15;
if(i<=100000)
bouns=i*0.1;
else if(i<=200000)
bouns=bouns1+(i-100000)*0.075;
else if(i<=400000)
bouns=bouns2+(i-200000)*0.05;
else if(i<=600000)
bouns=bouns4+(i-400000)*0.03;
else if(i<=10000000)
bouns=bouns6+(i-600000)*0.15;
else
bouns=bouns10+(i-1000000)*0.01;
printf("bouns=%d",bouns);//输出一个数据a为整形数据。
}
星期
int day;
cout<<"输入数:";
cin>>day;
switch (day)
{
case 0:
cout<<"sunday"<<endl;
break;
case 1:
cout<<"monday"<<endl;
break;
cout<<"tuesday"<<endl;
break;printf怎么加endl
case 3:
cout<<"wednesday"<<endl;
break;
case 4:
cout<<"thursday"<<endl;
break;
case 5:
cout<<"friday"<<endl;
break;
case 6:
cout<<"saturday"<<endl;
break;
default:
cout<<"day out of range sunday ..saturday"<<endl;
break;
}
return 0;
比拟XY大小
#include<iostream>
using namespace std;
int main()
{int x,y;
cout<<"Enter x and y:";
cin>>x>>y;
if(x!=y)
if(x>y)
cout<<"x>y"<<endl;
if(x<y)
cout<<"x<y"<<endl;
else
cout<<"x=y"<<endl;
return 0;
}
年可以被4或者400整除不能被100整除;#include<iostream>
using namespace std;
{
int year;
bool isLeapYear;
cout<<"Enter the year:";
cin>>year;
isLeapYear=((year%4==0&&year%100!=0||year%400==0));
if(isLeapYear)
cout<<year<<"is a leap year"<<endl;
else
cout<<year<<"is not leap year"<<endl;
return 0;
}
【程序1】
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去
掉不满足条件的排列。
2.程序源代码:
#include<iostream>
Int main()
{
int i,j,k;
printf("\n");
for(i=1;i<5;i++)/*以下为三重循环*/ for(j=1;j<5;j++)
for (k=1;k<5;k++)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。