zoukankan      html  css  js  c++  java
  • C语言 · 乘法表

    问题描述
      输出九九乘法表。
    输出格式
      输出格式见下面的样例。乘号用“*”表示。
    样例输出
    下面给出输出的前几行:
    1*1=1
    2*1=2 2*2=4
    3*1=3 3*2=6 3*3=9
    4*1=4 4*2=8 4*3=12 4*4=16
    ……
     
    1 #include<stdio.h>
    2 int main(){
    3     int i,j,n;
    4     for(i=1;i<=9;i++){
    5         for(j=1;j<=i;j++)
    6             printf("%d*%d=%d ",i,j,i*j);
    7         printf("
    ");
    8     }
    9 }

    格式更加漂亮一点的(但是输出样式不符题意):

     1 #include<stdio.h>
     2 int main(){
     3     int i,j,n;
     4     printf("
    ");
     5     for(i=1;i<=9;i++){
     6         for(j=1;j<=i;j++)
     7             printf("%d*%d=%2d  ",i,j,i*j);
     8         printf("
    ");
     9     }
    10     
    11     printf("
    ");printf("
    ");
    12     
    13     for(i=1;i<=9;i++){
    14         // 将下面的for循环注释掉,就输出左下三角形
    15         for(n=1; n<=9-i; n++)
    16             printf("        ");
    17         for(j=1;j<=i;j++)
    18             printf("%d*%d=%2d  ",i,j,i*j);
    19         
    20         printf("
    ");
    21     }
    22 }
  • 相关阅读:
    各职业岗位说明
    感慨集中所
    批量插入测试数据
    写作技巧
    Cordova学习
    CocoStudio
    maven使用感受
    org.json
    ApplicationContext
    2017
  • 原文地址:https://www.cnblogs.com/panweiwei/p/6252378.html
Copyright © 2011-2022 走看看