I'm trying to perform various operations on an array
EDIT: I forgot that some people on the internet prefer to ignore obvious things.
1. I need to create an int array with 50 elements. This is not a question, this is a statement so you can understand what int alhpa[50] is and why it's there when you see it.
2. I need to initialize all of the elements to -1. This is not a question this is a statement, it's here so when you see for(int i = 0; i < 49; i++){alpha[i] = -1} you know why it's there and you'll realize that I had to do it this way.
3. I need to print out the first element, this is a statement and when you see the for loop that does this you'll know why it's there.
4. I need to manipulate the 25th element in the array so that it has a value of 62, this is not a question this is a statement, how ever if you've got a better way of doing it I would love to hear your idea (i'm still learning)
5. I need to manipulate the tenth element so that it has a value of the fiftieth^3 + 10 . This is not a question this is a statement, it's here so that you don't ask me why and what the for loop is that performs this operation. If you know a better way to do it I would love to hear your idea...
6.I need to use a for loop to output a component of alpha if it's index is a multiple of 2 or 3 how do I do this? This is a question. ^
7.I need to output the last element in the array, how do I do this?
This is a question ^
8.I need to output the entire array (after having formatted the output) to print 15 elements per line, how do I do this?
This is a question ^
9. I need to use a for loop to increment every other element (the even indexed elements), how do I do this?
This is a question^
10. I need to make another array that will contain the differences between consecutive elements in alpha, how do I do this?
This is a question ^
Yes it's a lot I know and I will apreciate any help with this!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <array>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int alpha[50],
element_1,
element_25,
last_element;
for (int i = 0; i < 49; i++)
{
alpha[i] = -1;
element_1 = alpha[i];
// initializes all elements to have a value of -1
}
for (int i = 0; i < 1; i++)
{
cout <<"The first element is: " << alpha[i] << endl;
// Displays the first element in the array
}
for (int i = 0; i < 24; i++)
{
alpha[24] = 62;
element_25 = alpha[i];
// Sets the 25th element to have a value of 62
}
for (int i = 0; i < 49; i++)
{
int val = pow(alpha[49], 3) + 10;
// Takes the value of the fiftieth element performs the above operation (value of element 50 to the third power + 10)
for (int j = 0; j < 9; j++)
{
alpha[9] = val;
/*
stores the value of val in the 10th element (-1 * -1 * -1 + 10 = 9)
*/
}
}
/*
for (int i = 0; i < 49 && i % 2 == 0; i++)
{
cout << alpha[i] << endl;
pseudo code here... while i is less than 50 and if i can be divided by 2 evenly advance i, and print i for each advanced position.
and to be more clear I'm attempting to print the index not the values in the array, so for example if index[4] / 2 = 0; etc..
}
for (int i = 0; i < 49 && !i % 2 == 0; i++)
{
cout << alpha[i] << endl;
pseudo code here... while i is less than 50 and if i can not be divided by 2 evenly ( as in if we have a remainder) advance i, and print i for each advanced position.
and to be more clear I'm attempting to print the index not the values in the array, so for example if index[7] / 3 != 0; etc..
}
*/
for (int i = 48; i < 49; i++)
{
cout << "\nThe last element is: " << alpha[49] << endl;
// Supposed to display the last element, it does not.
}
for (int i = 0; i < 49; i++)
{
for (int j = 0; j < 15; j++)
{
cout << "\t" << alpha[j];
}
cout << endl;
/*
These two for loops are supposed to print the entire array, but it's also supposed to break down the array so that it prints out 15 values per line
It does print print 15 per line but it resets its self and prints the same 15 values each loop.
*/
}
/*
for (int i = 0; i < 50; i++)
{
cout << alpha[i] << endl;
}
*/
return 0;
}
|
That's only part of what I need to, I've not yet finished all the problems I outlined above this is just a starting point.