Thursday 22 August 2013

Print Table program in C#

Q:- Write table of 2 using for loop in C# ???



Ans:- using System;
using System.Collections.Generic;
using System.Text;

namespace codeforevenorodd
{
    class Program
    {
        static void Main(string[] args)
        {
          
           
            for(int i=1;i<11;i++)
            {
          int num=2*i;
            Console.WriteLine(num);
            }
            Console.ReadLine();
        }
        }
    }
 

2 comments:

  1. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp63
    {
    class Program
    {
    static void Main(string[] args)
    {
    int a, b, c, d;
    Console.Write("enter a value \t");
    a = Convert.ToInt32(Console.ReadLine());

    Console.Write("enter b value \t");
    b = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("\nYour required table is as under.\n\n--------------------------------\n");
    for (d = 1; d <= b; d++)
    {
    c = a * d;
    Console.WriteLine("{0} * {1} = {2} \n", a, d, c);


    }
    Console.ReadLine();


    }
    }
    }

    ReplyDelete
  2. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp63
    {
    class Program
    {
    static void Main(string[] args)
    {
    int a, b, c, d;
    Console.Write("enter a value \t");
    a = Convert.ToInt32(Console.ReadLine());

    Console.Write("enter b value \t");
    b = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine("\nYour required table is as under.\n\n--------------------------------\n");
    for (d = 1; d <= b; d++)
    {
    c = a * d;
    Console.WriteLine("{0} * {1} = {2} \n", a, d, c);


    }
    Console.ReadLine();


    }
    }
    }

    ReplyDelete