Problem 1 write a c program that reads an integer n generate
Problem (1): write a c# program that reads an integer n, generate cube of the integer n read by calling the cube function. Continue the computation while n! = 0.
EX:
• Enter a value 5 Cube of 5 is 125
• Enter a value Cube of 2 is 8
• Enter a value 0 Cube of 0 is 0
Problem (2): Write a C# program to read 5 real numbers (Use an array of size 5 to store elements) and then print them in order and reverse order. Define functions ReadDepositArray, ShowDepositArrayInorder, and ShowDepositArrayReverse to perform this task.
Problem (3): The power function can be made faster by having it calculate x^n in a different way. We first notice that if n is a power of 2, then x^n can be computed by squaring. For example, x^4 is a square of x^2, so x^4 can be computed using only two multiplication instead of three. As it happens, this technique can be used even when n is not a power of 2. If n is even, we use the formula x^n = (x^n/2) ^2. If n is odd, then x^n = x times x^n-1. Write a recursive function that computes x^n.(The recursion ends when n=0, in which case the function returns 1.) To test your function, write a C# program that asks the user to enter values for x and n, calls power to compute x^n, and then displays the value returned by the function.
Solution
//1
using System;
 
 namespace cube
 {
     class Program
     {
         public static void Main(string[] args)
         {
             int n=-1;
             while(n!=0){
              Console.WriteLine(\"Enter an integer: \");
             n=Convert.ToInt32(Console.ReadLine());
              Console.WriteLine(\"Cube of \"+n +\" is \"+(n*n*n));
             }
              
              Console.ReadKey(true);
          }
     }
 }
////////////////////////////////////////////////////
//2.
using System;
 
 namespace Array
 {
     class Program
     {
         public static void Main(string[] args)
         {
             int []array=new int[5];
             ReadDepositArray(array);
              ShowDepositArrayInorder(array);
              ShowDepositArrayReverse(array);
              
              
              Console.ReadKey(true);
          }
         static void ReadDepositArray(int []array)
         {
             Console.WriteLine(\"Enter the array elements\");
             for(int i=0;i<5;i++){
                 Console.WriteLine(\"# \"+(i+1));
                 array[i]=Convert.ToInt32(Console.ReadLine());
               }
          }
         
         static void ShowDepositArrayInorder(int []array)
         {
             Console.WriteLine(\"Array elements are \");
             for(int i=0;i<5;i++){
                 Console.Write(array[i]+\" \");
              }
              Console.WriteLine(\" \");
         }
         
         static void ShowDepositArrayReverse(int []array)
         {
             for(int i=0;i<5;i++)
             {
                  for(int j=0;j<5;j++)
                 {
                      if(array[i]>array[j])
                      {
                          int t=array[i];
                         array[i]=array[j];
                          array[j]=t;
                      }
                  }
              }
              Console.WriteLine(\"Array elements in Reversal Order \");
             for(int i=0;i<5;i++){
                 Console.Write(array[i]+\" \");
              }
          }
     }
 }


