Here in this, we will code a program that will accept an integer from a user and print a table for that number.
For example, if the user enters 7 then the program will print the table of 7.
Multiples of a Number
C++:
#include<iostream.h> #include< conio.h> #include<stdio.h> #include<math.h> void main() { clrscr(); int n; cout<<" Enter a number: "; cin>>n; for(int i =1; i<=10;i++) cout<<n<<"*"<<i<<"= "<<i*n<<"\n"; getch(); }
Output:
Enter a number: 10 10*1= 10 10*2= 20 10*3= 30 10*4= 40 10*5= 50 10*6= 60 10*7= 70 10*8= 80 10*9= 90 10*10= 100
Python:
n= int(input("Enter a number: ")) for i in range(1,11): print(str(n)+"*"+str(i)+"=",i*n)
Output:
Enter a number: 7 7*1= 7 7*2= 14 7*3= 21 7*4= 28 7*5= 35 7*6= 42 7*7= 49 7*8= 56 7*9= 63 7*10= 70
People are also reading:
- WAP to find the divisors of a positive Integer
- Python Program To Display Powers of 2 Using Anonymous Function
- WAP to Calculate Simple Interest
- Python Program to Find LCM
- WAP in C++ & Python to find whether a number is a palindrome or not
- Programming in C and Java to convert from octal to decimal
- WAP to convert a given number of days into years, weeks and days
- Python Program to Print the Fibonacci sequence
- WAP to calculate the sum of two numbers
- Python Program to Count the Number of Each Vowel