首页 > 代码库 > 九九乘法表

九九乘法表

#include <stdio.h>                                              
#include <stdlib.h>

int main()
{
    int i , j , k , a ;
    scanf(" %d",&a);                                             //输入数字a
    if(a == 1)                                                        //对a进行判断,当a为1时,输出只有下半部分的九九乘法表
    {
    for(i = 1;9 >= i;i++)                                        
        {
            printf ("\n");                                          //在横排开始循环时换行
            for(j = 1;j <= i;j++)
            {
                k = i*j;
                printf(" %d * %d = %2d",i,j,k);           //输出乘法表达式,运算结果输出最少为两位
            }
        }
     }
     else                                                              //对a进行判断,当a不为1时,输出全部的九九乘法表
     {
            for(i = 1;9 >= i;i++)
        {
            printf ("\n");
            for(j = 1;j <= 9;j++)
            {
                k = i*j;
                printf(" %d * %d = %2d",i,j,k);         
            }
        }
     }
    return 0;
}