0% found this document useful (0 votes)
8 views1 page

C++ Array Manipulation: Squares and Triples

This C++ program creates an array of 50 double elements. It squares the first 25 indices and takes 3 times the index for the remaining elements. It then displays the array contents with 10 numbers per line to the screen.

Uploaded by

Roderick Bennett
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

C++ Array Manipulation: Squares and Triples

This C++ program creates an array of 50 double elements. It squares the first 25 indices and takes 3 times the index for the remaining elements. It then displays the array contents with 10 numbers per line to the screen.

Uploaded by

Roderick Bennett
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

/*

*/

Author: Roderick Bennett


Class: C++ Programming Online, Fall 2013
Assignment: Chapter 8, Programming Exercise 1
This program creates an array named Alpha of 50 components of type double.
The output of the program computes the square of the first 25 indices and
Takes 3 times the index of the remaining indices. The output is displayed
on the screen with ten numbers per line.

#include <iostream>
using namespace std;
const int N = 50;
int main()
{
int alpha[N];
for (int i = 0; i < N; i++)
{
if (i < 25)
{
alpha[i] = i*i;
}
else
alpha[i] = 3 * i;
}
cout << "The contents of the array alpha are: \n\n";
for (int j = 0; j < N; j++)
{
cout << alpha[j] << " ";
if ((j + 1) % 10 == 0)
cout << endl;
}
cout << endl << endl;
system("pause");
return 0;
}

You might also like