Multiplication Table of any number till 12

 

Multiplication Table of any number till 12


C Program
1.For Loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
  int i,n,Ans;
  printf("Enter Any Number:");
  scanf("%d",&n);
  for(i=1;i<=12;i++)
  {
      Ans = 0;
      Ans = i * n;
      printf("%d * %d = %d\n", i, n, Ans);
  }
}
2.While Loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
  int i,n,Ans;
  printf("Enter Any Number:");
  scanf("%d",&n);
     i=1;
     while(i<=12)
   {
      Ans = 0;
      Ans = i * n;
      printf("%d * %d = %d\n", i, n, Ans);
      i++;
    }
}
3.Do While Loop
#include <stdio.h>
#include <stdlib.h>
int main()
{
  int i,n,Ans;
  printf("Enter Any Number:");
  scanf("%d",&n);
     i=1;
    do
   {
       Ans = 0;
      Ans = i * n;
      printf("%d * %d = %d\n", i, n, Ans);
      i++;
    }while(i<=12);
}


Java Program
1.For Loop
import java.util.Scanner;

public class MultiplicationTable {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.print("Enter Any Number:");
		int n = s.nextInt();
		 for(int i=1;i<=12;i++)
		  {
		      int Ans = 0;
		      Ans = i * n;
		      System.out.println(i+ "*" + n+ "= " + Ans );
		  }
	
	}
}
2.While Loop
import java.util.Scanner;

public class MultiplicationTable {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.print("Enter Any Number:");
		int n = s.nextInt();
		int i=1;
		while(i<=12)
		   {
		      int Ans = 0;
		      Ans = i * n;
		      System.out.println(i+ "*" + n+ "= " + Ans );
		      i++;
		    }
	
	}
}
3.Do While Loop
import java.util.Scanner;

public class MultiplicationTable {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.print("Enter Any Number:");
		int n = s.nextInt();
		int i=1;
		 do
		   {
		      int Ans = 0;
		      Ans = i * n;
		      System.out.println(i+ "*" + n+ "= " + Ans );
		      i++;
		    }while(i<=12);
	
	}
}

0 Comments:

Post a Comment