计算s[n]=a+aa+aaa+aa...a(n个)的值
#include <iostream>
using namespace std;
int main()
{
int a,n,i,j,b=0;
long unsigned int s=0;
cout<<"请输入数字a:"<<endl;
cin>>a;
cout<<"请输入数字n:"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
i=n;
for(j=1;j<=i;j++)
{
b=b*10+a;
}
s+=b;
b=0;
}
cout<<"经计算得"<<"s["<<n<<"]="<<s<<endl;
return 0;
}
打印九九乘法表
#include<iostream>
using namespace std;
int main()
{
int i,j,s;
cout<<"九九乘法"<<endl;
for(j=1;j<10;j++)
{
for(i=1;i<=j;i++)
{
s=i*j;
cout<<i<<"*"<<j<<"="<<s<<' ';
}
cout<<endl;
}
}
两个羽毛队进行单打比赛
#include<iostream>
using namespace std;
int main()
{
cout<<"张三和宋八对打.\n";
cout<<"李四和陈六对打.\n";
cout<<"王五和赵七对打.\n";
return 0;
}