+500
 



C# program to print 1 2 4 8 16 21 64 128 …nth iteration

Program Statement:
Write a program using for loop which prints the following series.
1 2 4 8 16 21 64 128 …nth iteration

Solution:

static void Main(string[] args)
        {
            int n,i=1,num=1;
            Console.WriteLine("Enter Value of n ");
            n = Convert.ToInt32(Console.ReadLine());
            Console.Write(i+" ");
            for (i = 1; i <= n; i++)
            {
                num = num * 2;
                Console.Write(num + " ");
            }
            
            Console.ReadLine();
        }



Post a Comment

 
Top