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.
#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;
}
Comments
Leave a comment