PAT基础编程题目-7-20 打印九九口诀表

PAT基础编程题目-7-20 打印九九口诀表

题目详情

PAT基础编程题目-7-20 打印九九口诀表_第1张图片
PAT基础编程题目-7-20 打印九九口诀表_第2张图片

题目详情:https://pintia.cn/problem-sets/14/problems/800

解答

C语言版

#include
int main() {
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= i; j++) {
			printf("%d*%d=%-4d", j, i, i * j);
		}
		if (i<N)
			printf("\n");
	}
	return 0;
}

PAT基础编程题目-7-20 打印九九口诀表_第3张图片

C++版

#include
#include
using namespace std;
int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= i; j++) {
			cout << j << "*" << i << "=" << setw(4) << setiosflags(ios::left) << i * j;
		}
		if (i < N)
			cout << endl;
	}
	return 0;
}

PAT基础编程题目-7-20 打印九九口诀表_第4张图片

Java版

import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		int N = 0;
		Scanner scanner = new Scanner(System.in);
		if (scanner.hasNext()) {
			N = scanner.nextInt();
		}
		scanner.close();
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(j+"*"+i+"="+String.format("%1$-4d", i*j));
			}
			if (i < N)
				System.out.println();
		}

	}

}

PAT基础编程题目-7-20 打印九九口诀表_第5张图片

创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!

你可能感兴趣的:(PAT基础编程题目-7-20 打印九九口诀表)