Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Input any mathematical table without using loops

I need to print mathematical table without using any loop (for, while, do while, etc.). Can anyone help me out, the easiest example I could find was writing console.writeline 10times for each line.

This is my code!

using System;
using System.Linq;
class Question4
{

 int product, i=1;
  public static void Main(string[] args)
 {
  int num;
  Console.Write("Enter the Number to Print its Multiplication Table: ");
  num = Convert.ToInt32(Console.ReadLine());
  Console.WriteLine("\nMultiplication Table For {0}: ",num);
  TableFunctionName (num);
   }
   public void TableFunctionName(int n)
  {
   if(i<=10)
  {
   table=n*i;
    Console.WriteLine("{0} x {1} = {2}",n,i,table);
    i++;
     }
   return;

     }

     }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using recursion

  static   void Multiply(int a, int b) {
        if (a > 1)
            Multiply(a - 1, b);
        Console.WriteLine($"{a} * { b} = {a * b}");
    }
    static void Main(string[] args) {

        Multiply(10, 5);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading