Multiplication Table of any number

 In this I will let You know how to create a multiplication table of   the number you want .So, without any time waste .What we are going to use here .We here use loop. Then question come what is loop for understanding let me give you example if you want to print 1000 natural numbers for that you are  not going to  print one by one in order to save time. For this we just create a loop condition after which it exit and then increase it one by one .

Code:

Multiplication table using While loop

#include<stdio.h>
//to print multiplication table of any number
int main(){
    
    int number;
    int i=1;//we here intilize it form one 
    printf("Enter Number for Multiplication table\n");
    scanf("%d",&number);
    while(i<=10){
        printf("%d X %d = %d\n",number,i,number*i);
        i++;
    }

    return 0;
}

Multiplication Table using for loop

#include<stdio.h>
//to print multiplication table of any number
int main(){
    
    int number;
    int i=1;//we here intilize it form one 
    printf("Enter Number for Multiplication table\n");
    scanf("%d",&number);
    for(i=1;i<=10;i++){
        printf("%d x %d = %d\n",number,i,number*i);
    }

    return 0;
}

Multiplication Table using do-while loop

#include<stdio.h>
//to print multiplication table of any number
int main(){
    
    int number;
    int i=1;//we here intilize it form one 
    printf("Enter Number for Multiplication table\n");
    scanf("%d",&number);
    do{
        printf("%d x %d = %d\n",number,i,number*i);
        i++;
    }while(i<=10);

    return 0;
}

Logic:

Now you can see here we first declare Variable of type int  number .And we take input form user in it and also define i initialize i it form 1. And increase value of i every time till i less than equal to  10. After this we just do multiplication of  given number from user by value of i. And it will print us multiplication table.

Output:


You can see here I give 12 as input  and program here give us multiplication table of  12. You can check out this on your own pc .I hope you find this helpful to  you in your work .

Thanks for reading 




No comments:

Post a Comment