Tuesday, July 27, 2010

// dfgdfdfg.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
// within iostream
// istream cin;
// ostream cout;
using namespace std;

bool aComposite[1024] = { true, true };
bool isPrime(int n)
{
    return ! aComposite[n];
}

void setupLookupTable()
{
    for (int i = 2; i < 1024; i++)
    {
        // is this number i am visiting
        // already marked off as composite
        if (aComposite[i] == false)
            for (int j=i+i; j < 1024; j+=i)
                aComposite[j] = true;
    }

}

void print(const int a[], int capacity)
{
    for (int i = 0; i < capacity; i++)
        cout << a[i] << ' ';
    cout << endl;
}

void add(const int a[], const int b[], int c[], int capacity)
{
    for (int i = 0; i < capacity; i++)
        c[i] = a[i] + b[i];
}

void subtract(const int a[], const int b[], int c[], int capacity)
{
    for (int i = 0; i < capacity; i++)
        c[i] = a[i] - b[i];
}

void mult(const int a[], int scalar, int b[], int capacity)
{
    for (int i = 0; i < capacity; i++)
        b[i] = a[i] * scalar;
}

int main() {
    setupLookupTable();
    for(int k = 0; k < 1024; k++)
        if (isPrime(k))
            cout << k << endl;
    string s, t;
    int u;

    ifstream jin;
    jin.open("c:/josh/myfirstinput.txt");
    jin >> s;
    jin >> t;
    cout << s << t << endl;
    jin.close();

    ofstream jout;
    jout.open("c:/josh/myfirstoutput.txt");
    for(int i = 0; i < 10; i++)
        jout << i << " ";
    jout << endl;
    jout.close();
    system("PAUSE");

   int A[3][3] =
   {
       { 4, 6, 0},
       { 6, 0, 1},
       { -1,3, 5}
   };
   int B[3][3];
   int C[3][3];
   int x[5] = {3,4,5,2,3};
   int y[5] = {1,1,0,2,3};
   int z[5];
   int a[5];
    // a = x * 6
   add(x, y, z, 5);

   print(z, 5);

   mult(y, 6, z, 5);
   print(z, 5);
  
   return 0;
}

No comments:

Post a Comment