-
cool but simple
i just learnt about arrays and am good at maths so i wrote two simple progs that calculate squares and the fibonacci numbers here they are
Code:
#include <iostream>
using namespace std;
int main()
{
int i;
int fib[20];
fib[0] = 1;
fib[1] = 1;
for (i = 2; i < 20; i++)
{
fib[i] = fib[i-1] + fib[i-2];
}
for (i = 0; i < 20; i++)
{
cout << "The " << i+1 << " element is " << fib[i] << endl;cin.get();
}
return 0;
}
-
hres the square
Code:
#include <iostream>
using namespace std;
int main()
{
int square[100];
int i;
int k;
for (i = 0; i < 100; i++) {
k = i + 1;
square[i] = k*k;
cout << "The square of " << k << " is " << square[i] << endl;cin.get();
}
return 0;
}
-