solve this question and show answer step by step Write a pro

solve this question and show answer step by step
Write a program that declares an array of 50 of the double data type. Initialize the array so that the first 25 components are equal to the square of the index variable, and the last 25 are equal to the cubed of the index variable. Output is to be 10 values per line.

Solution

#include<stdio.h>

main()
{
   double arr[50];
   int i;
   for(i=0;i<50;i++)
   {
       if(i<25)
       arr[i]=i*i;//to calculate and store square of its index
       else
       arr[i]=i*i*i;//to calculate and store cube of its index
   }
   for(i=0;i<50;i++)
   {
       printf(\"%f \",arr[i]);
       if(i%10==0&&i!=0) // to print a new line each after 10 values printed in a line
           printf(\"\ \");
   }
}


solution:

0.000000 1.000000 4.000000 9.000000 16.000000 25.000000 36.000000 49.000000 64.000000 81.000000 100.000000

121.000000 144.000000 169.000000 196.000000 225.000000 256.000000 289.000000 324.000000 361.000000 400.000000

441.000000 484.000000 529.000000 576.000000 15625.000000 17576.000000 19683.000000 21952.000000 24389.000000 27000.000000

29791.000000 32768.000000 35937.000000 39304.000000 42875.000000 46656.000000 50653.000000 54872.000000 59319.000000 64000.000000

68921.000000 74088.000000 79507.000000 85184.000000 91125.000000 97336.000000 103823.000000 110592.000000 117649.000000

solve this question and show answer step by step Write a program that declares an array of 50 of the double data type. Initialize the array so that the first 25

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site