| | |
for loop help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Solved Threads: 0
i wrote in my prog
#include <iostream>
using namespace std;
int main ( )
{
int arraysize = 25;
int a [arraysize] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 }
wut kinda for loop do i need to print out 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 these numbers in reverse order..i used array for this programme.
#include <iostream>
using namespace std;
int main ( )
{
int arraysize = 25;
int a [arraysize] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 }
wut kinda for loop do i need to print out 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 these numbers in reverse order..i used array for this programme.
Greetings bryan7890,
Do you want to print those numbers in reverse order as in starting at the last array and read until the first, or are you trying to sort the array to ascend or descend accordingly?
- Stack Overflow
Do you want to print those numbers in reverse order as in starting at the last array and read until the first, or are you trying to sort the array to ascend or descend accordingly?
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Solved Threads: 0
this is C++ question
Write a complete program that staticaly declares an array with the following values:
2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3
and manipulates the resulting array so that the values in the array and reversed.
Print out the new array, which should look as follows:
-3, 0, 242, 324, 62, 64, 35, 57, 19, 21, 29, 35, 62, 93, 82, 45, -3, 123, 35, 20, 4, 19, 5, 3, 2
Note:
- you must use for-loop structure in order to complete your manipulations
- you may use only one (1) array - cannot create second array
Write a complete program that staticaly declares an array with the following values:
2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3
and manipulates the resulting array so that the values in the array and reversed.
Print out the new array, which should look as follows:
-3, 0, 242, 324, 62, 64, 35, 57, 19, 21, 29, 35, 62, 93, 82, 45, -3, 123, 35, 20, 4, 19, 5, 3, 2
Note:
- you must use for-loop structure in order to complete your manipulations
- you may use only one (1) array - cannot create second array
•
•
Join Date: Oct 2004
Posts: 13
Reputation:
Solved Threads: 0
#include <iostream>
using namespace std;
int main()
{
int a [] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324\
, 242, 0, -3 };
int size = sizeof(a);
cout << size << endl << endl;
for(int i = 0; i <= size; i++)
{
cout << a[i] << " ";
}
}
y i m geeting this kinda output..
2 3 5 19 4 20 35 123 -3 45 82 93 62 35 29 21 19 57 35 64 62 324 242 0 -3 -4260908 5 -4260800 0 0 1 -4260916 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -4260680 0 -4260674 -4260650 -4260637 -4260623 -4260604 -4260597 -4260428 -4260392 -4260353 -4260340 -4260326 -4260302 -4260289 -4260255 -4260238 -4260230 -4260177 -4260161 -4260152 -4260124 -4260099 -4260088 -4260079 -4259905 -4259898 -4259878 0 2008 -4259868 2014 -4259850 3 65588 4 32 5 5 9 67004 7 -12910592 8 2816 6
and numbers are not in reverse order..
using namespace std;
int main()
{
int a [] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324\
, 242, 0, -3 };
int size = sizeof(a);
cout << size << endl << endl;
for(int i = 0; i <= size; i++)
{
cout << a[i] << " ";
}
}
y i m geeting this kinda output..
2 3 5 19 4 20 35 123 -3 45 82 93 62 35 29 21 19 57 35 64 62 324 242 0 -3 -4260908 5 -4260800 0 0 1 -4260916 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -4260680 0 -4260674 -4260650 -4260637 -4260623 -4260604 -4260597 -4260428 -4260392 -4260353 -4260340 -4260326 -4260302 -4260289 -4260255 -4260238 -4260230 -4260177 -4260161 -4260152 -4260124 -4260099 -4260088 -4260079 -4259905 -4259898 -4259878 0 2008 -4259868 2014 -4259850 3 65588 4 32 5 5 9 67004 7 -12910592 8 2816 6
and numbers are not in reverse order..
Well,
kakilang's for loop looked like: While yours looks like The difference is that you start at 0 [the beginning] and looping until the end. kakilang's example starts at the end, and loop until the beginning decrementing instead of incrementing.
Also, C provides a compile-time unary operator called sizeof that can be used to compute the size of any object. Here, we are not looking to find the size of the object, our goal is to know the size of our array. By simply creating the array with a fixed number of 25 may help. For example: Where the ... means to keep going. This was just an example, and hopefully it helps.
If you have further questions, please feel free to ask.
- Stack Overflow
kakilang's for loop looked like:
for(int i = 24; i >= 0; i--)
for(int i = 0; i <= size; i++)
Also, C provides a compile-time unary operator called sizeof that can be used to compute the size of any object. Here, we are not looking to find the size of the object, our goal is to know the size of our array. By simply creating the array with a fixed number of 25 may help. For example:
#define SIZE 25 int main() { int i, a[SIZE] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 }; // Start at end; decrement to beginning for (i = SIZE-1; i >= 0; i--) ...
If you have further questions, please feel free to ask.
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
![]() |
Similar Threads
- Excel 2007 - infinite code loop (Windows Software)
- Help with gui loop. (C)
- Loop...without the loop (Java)
Other Threads in the C++ Forum
- Previous Thread: problem creating a for loop for an array
- Next Thread: Im new
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





