Write a Program to Print the 1 to 10 Multiples of a Number

Posted in

Write a Program to Print the 1 to 10 Multiples of a Number
vinaykhatri

Vinay Khatri
Last updated on June 15, 2024

    Multiples is one of the most important concepts of mathematics used in the real world. We all have learned tables in childhood, which help us find multiples of a given number.

    Here, in this article, we will write a program in C, C++, Python, and Java that will accept an integer from a user and print a table for that number, i.e., 1 to 10 multiples of a number.

    For example, if the user enters 7, the program will print the table of 7.

    What is a Multiple of a Number?

    A multiple of a given number is a product of the given number and some other natural number. For instance, the given number is 7, and we multiply 7 with some other natural number, say 3, 7*3 = 21. Hence, 21 is the multiple of 7, and 7 and 3 are factors of 21.

    Properties of Multiples of a Number

    • Every multiple of a number is greater than or equal to that number. For instance, the multiples of 5 are 5, 10, 15, 20, 25, etc. We can observe that each multiple is greater than or equal to 5.
    • Each given number has infinite multiples. For example, the multiples of 7 are 7, 14, 21, 28, 35, etc., and the list goes on.
    • Every number is a multiple of itself. For instance, 9 is the multiple of 9, as the multiples of 9 are 9, 18, 27, 36, etc.
    • If A is a multiple of B, A is exactly divisible by B. For example, 35/7 = 5, as 35 is the multiple of 7.

    1. C Program to Print the 1 to 10 Multiples of a Number

    #include<stdio.h>
    int main()
    {
       int n;
       printf("Enter a number: ");
       scanf("%d", &n);
       for(int i =1; i<=10;i++)
       {
           printf("\n%d*%d = %d ",n,i,n*i);
       }
    return 0;
    }

    Output:

    Enter a number: 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 

    2. C++ Program to Print the 1 to 10 Multiples of a Number

    #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

    3. Python Program to Print the 1 to 10 Multiples of a Number

    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

    4. Java Program to Print the 1 to 10 Multiples of a Number

    import java.util.*;
    public class Main 
    {
        public static void main(String[] args) 
        {
        Scanner s = new Scanner(System.in);
    	System.out.print("Enter a number:");        
    	int n=s.nextInt();
            for(int i=1; i <= 10; i++)
            {
                System.out.println(n+" * "+i+" = "+n*i);
            }
        }
    }

    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

    Conclusion

    This was all about writing a program in C, C++, Python, and Java to find the multiples of a given number. Our program uses a for loop to calculate 1 to 10 multiples of a given number. Try the above programs on your own and use other programming loops, such as while or do-while loops. When you implement a program on your system, you get a clear idea of how exactly the loop works.

    If you encounter any issue while implementing this program, do let us know in the comments.

    People are also reading:

    Leave a Comment on this Post

    0 Comments