Thread: cool but simple

  1. #1
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50

    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;
    }

  2. #2
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50
    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;
    }

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    good work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what SHOULD be a painfully simple API call...
    By Citizen Bleys in forum Windows Programming
    Replies: 3
    Last Post: 09-17-2003, 03:20 PM
  2. Simple simple graphics
    By triplem in forum C Programming
    Replies: 2
    Last Post: 05-19-2003, 02:52 AM
  3. simple graphic programing
    By mattyb in forum Game Programming
    Replies: 10
    Last Post: 12-30-2002, 09:56 PM
  4. File Input and Output, simple.
    By Vber in forum C Programming
    Replies: 5
    Last Post: 11-17-2002, 02:57 PM
  5. Trying to be cool
    By Theologian in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 08-19-2001, 06:17 AM