Seconds in a millenium?

I know this could be coded by simply doing..

1
2
3
4
5
int main()
{
   int retnum = (1000 * 365 * 24 * 60 * 60)
return(retnum)
}


But I am working with arrays so I want to know how to do it like this..

1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
   int n=0;
   int retnum=0;
   char Millenium[1000][365][24][60][60];

for (n;n<sizeof(Millenium);n++)
{ 
  retnum += n;
}
  return(retnum);
}


Any help here? I'm just trying to learn arrays, I know there are simpler ways of getting the seconds in a millenium, and believe me I really dont care how many there are. Another question I have, is the above code using the array coded right? It won't compile because it says the array is too large. I'm using Dev-C++ because I'm a cheapo ;)
Last edited on
Update: Changed the array to [1000][24] which should output 24000 but it outputted 287988000. So.. it's obviously not coded right somewhere in there.
Actually, 1000*365.2425*24*60*60, give or take a few minutes.
And your array would use 29.37 GB.

EDIT: Your loop is not properly coded. It should be retnum++. What you're doing right now is 0+1+2+3+...+n-1 (which, by the way, is the same as ((n-1)^2+n-1)/2).
Also, you could just do retnum=sizeof(Millenium).
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// arrays example
#include <iostream>
using namespace std;

int billy [] = {16, 2, 77, 40, 12071};
int n, result=0;

int main ()
{
  for ( n=0 ; n<5 ; n++ )
  {
    result += billy[n];
  }
  cout << result;
  return 0;
}


Thats where I got the idea but im tryin to do the same effect with a multidimensional array.
Oh, well then this is what you're trying to do:
1
2
3
4
float v[]={1000,365.2425,24,60,60,0};
float res=1;
for (int a=0;v[a];a++)
	res*=v[a];
Thanks, but the whole point of doing this is to figure out how to get that process done with a MULTIDIMENSIONAL array, getting the numbers not important to me. That way you had it set up was a single dimensional array with an array size of 6. So it looks like this..

 
[ 1000] [365.2425] [24] [60] [60] [0]


I'm looking for a MUTLIDIMENSIONAL array, so just random numbers if I declared an array by typing
int mdarray[2][5] it would look like this..

1
2
3
4
5
[x] [x]
[x] [x]
[x] [x]
[x] [x]
[x] [x]


Do you understand what I'm trying to do? You can use whatever example you want, I guess I'm just trying to see when a multidimensional array would be useful and how to go about initalizing and using it in a loop.
Last edited on
If you want to practice matrices, try calculating a Pascal's triangle (http://en.wikipedia.org/wiki/Pascal%27s_triangle ):
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

If you want to make it harder, do it memory efficient.
Last edited on
Topic archived. No new replies allowed.