C++九九乘法表

/*
题目:输出9*9口诀。
1.程序分析:分行与列考虑,共9行9列,i控制行,j控制列。
*/

#include <iostream>
using namespace std;
void main()
{
int i , j ;
for(i=1;i<9;i++);
{
for(j=1;j<i;j++);
{
cout<<i<<"*"<<j<<"="<<i*j;
}
cout<<endl;
}
}

结果输出结果是 9*9=81,怎么回事?

1.
首先创建主程序,在此我们声明了乘法表函数muti,主函数中,主要是调用该函数,实现九九乘法表的创建。

#include "stdafx.h"

#include <iostream>

void muti();

int main()

{

using namespace std;

muti();

cin.get();

cin.get();

return 0;

}

2.
然后是对muti函数的编写,在函数体中,我们定义了两个整型变量,通过双重for循环实现1*1至9*9的乘法过程,输出通过cout和endl,并在每句输出后面加上空格即”\t”,完成整个制作过程

#include "stdafx.h"

#include <iostream>

void muti()

{

using std::cout;

using std::endl;

int i, j;

for (i = 1; i<10;
i++)

{

for (j = 1; j<=i;
j++)

{

cout
<< j << "*" << i << "=" << i*j<<"\t";

}

cout
<< endl;

}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-04-05
#include<stdio.h>
#include<stdlib.h>

void main()
{
for(int i=1;i<=9;i++)
{
for(int k=1;k<i;k++)
{
printf(" ");
}
for(int j=i;j<=9;j++)
{
printf("%d*%d=%-2d ",i,j,i*j);
}
printf("\n");
}
}
可以运行,你可以看看效果,不行hi我。
第2个回答  2019-10-11
#include
io.h
#include
system.h
main(){
cin>>a,b;
if(a<0||b<0||a>b||a>10||b>10)cout<<"输入范围不正确!";
for(i=1;i<=b;i++){
for(j=1;j<=a;j++)cout<<"a*"+i+"="a*i+"
";
cout<<"\n";
}
}
大概是这样子吧,没上机调试过。
第3个回答  推荐于2017-09-02
#include <iostream>
using namespace std;
void main()
{
int i , j ;
for(i=1;i<9;i++)
{
for(j=1;j<i;j++)
{
cout<<i<<"*"<<j<<"="<<i*j;
}
cout<<endl;
}
}本回答被提问者采纳
第4个回答  2020-05-04
加上cout<<setw(75-8*i)<<"
";
修改代码如下:
#include<iostream.h>
#include<iomanip.h>
void
main()
{
int
i,j,h;
for(i=1;i<=9;i++)
{
cout<<setw(75-8*i)<<"
";
for(j=i;j>=1;j--)
{
cout<<setw(3)<<j<<"*"<<i<<"="<<j*i;
}
cout<<endl;
}
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网