[Algorithms] multiplication table

python

#!/usr/bin/env python
# encoding=utf-8
# Date: 2016-08-25
# Author: [email protected]
# Purpose: Just for fun

TableLenth = int(raw_input("Input the Max lines you want:\n"))


for i in range(1, TableLenth+1):
        for j in range(1, i+1):
                result = i*j
                print "%s * %s = %s\t" % (i,j,result),
        print "\n"


shell

#!/bin/bash
# encoding=utf-8
# Date: 2016-08-25
# Author: [email protected]
# Purpose: Just for fun
read -p "Input the Max lines you want:" TableLenth
for i in $(seq 1 $TableLenth)
do
    for j in $(seq 1 $i)
    do
        result=$[$i * $j]
        echo -n -e "$i + $j = $result\t"
    done
echo -e "\n"
done


C




java


class MultiTable{

	public static void main(String[] args){

		int i,j;

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

				System.out.print(i + "*" + j + "=" + i*j + "\t");

			}
			System.out.print("\n");

		}

	}

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章