Answer to Question #181179 in C++ for luna

Question #181179

Write a program that declares an array alpha of 50 values of type double. Initialize the array so that the  first 25 values are equal to the square of the index variable, and the last 25 values are equal to the three times the index variable. Output the array so that 10 elements per line are printed.



1
Expert's answer
2021-04-14T04:22:23-0400
#include <iostream.h>

int main()
{
    double arr[50];

   for(int i=0;i<50;i++)
   {
   if(i<=25)
       {
           arr[i] =(i+1) * (i+1);
       }
       else
       {
           arr[i] = 3* (i+1);
       }
   }
    int disCount=0;
    for(i=0;i<50;i++)
   {
       cout<< " "<<arr[i] ;
        disCount++;

       if(disCount == 10)
       {
           disCount =0;
           cout<< "\n";
       }
   }
   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS