Python, C++, JavaScript 및 C를 사용하여 숫자의 곱셈표를 표시하는 방법

Python, C++, JavaScript 및 C를 사용하여 숫자의 곱셈표를 표시하는 방법

다른 언어를 사용하여 프로그래밍할 때 루프를 사용하여 몇 줄의 코드로 숫자의 곱셈표를 인쇄할 수 있습니다. 그러나 방법을 모르고 이것을 하는 것은 어렵습니다.





하지만 걱정하지 마세요. 이 기사에서는 Python, C++, JavaScript 및 C를 사용하여 숫자의 곱셈표를 인쇄하는 방법을 배웁니다.





최대 10까지의 숫자의 구구단 표시

먼저 10까지의 숫자에 대한 곱셈표를 표시하는 방법을 살펴보겠습니다.





문제 설명

번호가 주어졌습니다. 하나에 . 의 곱셈표를 인쇄해야 합니다. 하나에 10까지. 예시 : num = 5로 둡니다. 5의 곱셈 테이블:

5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

10까지의 숫자의 곱셈표를 표시하는 방법

아래 접근 방식에 따라 최대 10까지의 숫자의 곱셈 표를 표시할 수 있습니다.



  1. 1에서 10까지 루프를 실행합니다.
  2. 각 반복에서 주어진 숫자에 반복 번호를 곱합니다. 예를 들어- 주어진 숫자가 5이면 첫 번째 반복에서 5를 1로 곱합니다. 두 번째 반복에서 5를 2로 곱하는 식입니다.

최대 10까지의 곱셈표를 표시하는 C++ 프로그램

다음은 최대 10까지의 곱셈표를 표시하는 C++ 프로그램입니다.

// C++ program to print the multiplication table of a number up to 10
#include
using namespace std;
// Function to print the multiplication table of a number up to 10
void printTable(int num)
{
for (int i = 1; i <= 10; ++i)
{
cout << num << ' * ' << i << ' = ' << num * i << endl;
}
}
// Driver Code
int main()
{
int num = 5;
cout << 'Number: ' << num << endl;
cout << 'Multiplication table of ' << num << endl;
printTable(num);
return 0;
}

산출:





Number: 5
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

관련 항목: 배열의 모든 요소의 곱을 찾는 방법

최대 10까지의 숫자의 곱셈표를 표시하는 Python 프로그램

다음은 최대 10까지의 숫자의 곱셈표를 표시하는 Python 프로그램입니다.





영화를 무료로 볼 수 있는 앱
# Python program to print the multiplication table of a number up to 10
# Function to print the multiplication table of a number up to 10
def printTable(num):
for i in range(1, 11):
print(num, '*', i, ' =', num*i)

# Driver Code
num = 5
print('Number:', num)
print('Multiplication table of', num)
printTable(num)

산출:

Number: 5
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

관련된: Python에서 For 루프를 사용하는 방법

최대 10까지의 곱셈표를 표시하는 JavaScript 프로그램

다음은 최대 10까지의 곱셈표를 표시하는 JavaScript 프로그램입니다.

// JavaScript program to print the multiplication table of a number up to 10
// Function to print the multiplication table of a number up to 10
function printTable(num) {
for (let i = 1; i <= 10; ++i) {
document.write(num + ' * ' + i + ' = ' + num * i + '
');
}
}
// Driver Code
var num = 5;
document.write('Number: ' + num + '
');
document.write('Multiplication table of ' + num + '
');
printTable(num);

산출:

나는 항상 인터넷 익스플로러를 사용하지 않는다
Number: 5
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

C 최대 10까지의 숫자의 곱셈표를 표시하는 프로그램

다음은 최대 10까지의 곱셈표를 표시하는 C 프로그램입니다.

// C program to print the multiplication table of a number up to 10
#include
// Function to print the multiplication table of a number up to 10
void printTable(int num)
{
for (int i = 1; i <= 10; ++i)
{
printf('%d * %d = %d ⁠n', num, i, num*i);
}
}
// Driver Code
int main()
{
int num = 5;
printf('Number: %d ⁠n', num);
printf('Multiplication table of %d ⁠n', num);
printTable(num);
return 0;
}

산출:

Number: 5
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

주어진 범위까지 숫자의 구구단 표시

물론 10 이하의 구구단을 고수할 필요는 없습니다. 상위 레벨에 대해서도 그렇게 하는 방법을 아는 것이 중요하며 아래에서 필요한 모든 정보를 찾을 수 있습니다.

문제 설명

번호가 주어졌습니다. 하나에 그리고 범위 . 의 곱셈표를 인쇄해야 합니다. 하나에 그 범위까지. 예시 : num = 5, range = 14로 둡니다.

5에서 14까지의 곱셈 테이블:

5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

주어진 범위까지 숫자의 곱셈표를 표시하는 방법

아래 접근 방식에 따라 주어진 범위까지 숫자의 곱셈 표를 표시할 수 있습니다.

  1. 1에서 범위까지 루프를 실행합니다.
  2. 각 반복에서 주어진 숫자에 반복 번호를 곱합니다. 예를 들어- 주어진 숫자가 5이면 첫 번째 반복에서 5를 1로 곱합니다. 두 번째 반복에서 5를 2로 곱하는 식입니다.

주어진 범위까지 숫자의 곱셈표를 표시하는 C++ 프로그램

다음은 주어진 범위까지 숫자의 곱셈표를 표시하는 C++ 프로그램입니다.

// C++ program to print the multiplication table of a number
#include
using namespace std;
// Function to print the multiplication table of a number
void printTable(int num, int range)
{
for (int i = 1; i <= range; ++i)
{
cout << num << ' * ' << i << ' = ' << num * i << endl;
}
}
// Driver Code
int main()
{
int num = 5;
int range = 14;
cout << 'Number: ' << num << endl;
cout << 'Range: ' << range << endl;
cout << 'Multiplication table of ' << num << endl;
printTable(num, range);
return 0;
}

산출:

Number: 5
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

관련된: 파이썬에서 while 루프를 사용하는 방법

주어진 범위까지 숫자의 곱셈표를 표시하는 Python 프로그램

다음은 주어진 범위까지 숫자의 곱셈표를 표시하는 Python 프로그램입니다.

# Python program to print the multiplication table of a number
# Function to print the multiplication table of a number
def printTable(num, r):
for i in range(1, r+1):
print(num, '*', i, ' =', num*i)

# Driver Code
num = 5
r = 14
print('Number:', num)
print('Range:', range)
print('Multiplication table of', num)
printTable(num, r)

산출:

삭제 된 비디오가 무엇인지 찾는 방법
Number: 5
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

관련 항목: Python에서 목록과 함께 루프를 사용하는 방법

주어진 범위까지 숫자의 곱셈표를 표시하는 JavaScript 프로그램

다음은 주어진 범위까지 숫자의 곱셈표를 표시하는 JavaScript 프로그램입니다.

// JavaScript program to print the multiplication table of a number
// Function to print the multiplication table of a number
function printTable(num, range) {
for (let i = 1; i <= range; ++i) {
document.write(num + ' * ' + i + ' = ' + num * i + '
');
}
}
// Driver Code
var num = 5;
var range = 14;
document.write('Number: ' + num + '
');
document.write('Range: ' + range + '
');
document.write('Multiplication table of ' + num + '
');
printTable(num, range);

산출:

Number: 5
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

C 주어진 범위까지 숫자의 곱셈표를 표시하는 프로그램

다음은 주어진 범위까지 숫자의 곱셈표를 표시하는 C 프로그램입니다.

// C program to print the multiplication table of a number
#include
// Function to print the multiplication table of a number
void printTable(int num, int range)
{
for (int i = 1; i <= range; ++i)
{
printf('%d * %d = %d ⁠n', num, i, num*i);
}
}
// Driver Code
int main()
{
int num = 5;
int range = 14;
printf('Number: %d ⁠n', num);
printf('Range: %d ⁠n', range);
printf('Multiplication table of %d ⁠n', num);
printTable(num, range);
return 0;
}

산출:

Number: 5
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

더 나은 프로그래머가 되기 위한 기본 프로그래밍 원리 이해

이 기사에서는 루프의 힘을 사용하여 몇 줄의 코드로 숫자의 곱셈표를 표시하는 방법을 배웠습니다. 거의 모든 프로그래밍 언어에서 몇 줄의 코드로 구구단을 표시할 수 있습니다.

더 나은 프로그래머가 되고 싶다면 KISS(Keep It Simple, Stupid), DRY(Don't Repeat Yourself), Single Responsibility, YAGNI(You Aren't Going To Need It), 개방형/폐쇄형, 상속보다 구성 등. 이에 대한 가이드가 있으니 다음에는 그곳으로 가보는 것이 어떻겠습니까?

공유하다 공유하다 트위터 이메일 모든 프로그래머가 알아야 할 10가지 기본 프로그래밍 원칙

코드는 명확하고 유지 관리하기 쉬워야 합니다. 다음은 행동을 정리하는 데 도움이 되는 몇 가지 다른 프로그래밍 원칙입니다.

다음 읽기
관련 항목
  • 프로그램 작성
  • C 프로그래밍
  • 자바스크립트
  • 파이썬
  • 코딩 튜토리얼
저자 소개 유브라지 찬드라(60편 게재)

Yuvraj는 인도 델리 대학교의 컴퓨터 공학 학부생입니다. 그는 풀 스택 웹 개발에 열정적입니다. 그는 글을 쓰지 않을 때 다양한 기술의 깊이를 탐구하고 있습니다.

유브라지 찬드라가 참여한 작품 더보기

뉴스레터 구독

뉴스레터에 가입하여 기술 팁, 리뷰, 무료 전자책 및 독점 거래를 확인하십시오!

구독하려면 여기를 클릭하세요.