Computer Science 3300
Spring 2015
Section 001
Programming Assignment 0

Assigned: Monday, January 12
Due: Tuesday, January 20, 11:59pm

Table of contents

  1. Note about this assignment
  2. The assignment
  3. Submitting your work


Note about This Assignment

The purpose of this assignment is just to ensure that you know how to log into Linux, compile and run a program, and submit your solution.


The Assignment

Log into Linux. Start a terminal. Create a directory to hold your CSCI 3300 submissions, and a subdirectory of that to hold assignment 0. Open a text editor. Copy the following program into it and save it as file assn0.cpp. (Do not copy it by hand! Just copy and paste.)

// CSCI 3300
// Assignment: 0
// Author:     Karl Abrahamson
// File:       assn0.cpp
// Tab stops:  none

/* This program shows the greatest common divisor
   of two numbers that are read from the user.
*/

#include <cstdio>
using namespace std;

//===========================================
//             gcd
//===========================================
// gcd(a,b) returns the greatest common
// divisor of a and b.
//===========================================

long gcd(long a, long b)
{
  if(a == 0)
  {
    return b;
  }
  else
  {
    return gcd(b % a, a);
  }
}

//===========================================
//               main
//===========================================

int main(int argc, char** argv)
{
  long a, b;

  printf("gcd of which two numbers? ");
  if(scanf("%li%li", &a, &b) == 2)
  {
    printf("The gcd of %li and %li is %li.\n", a, b, gcd(a,b));
  }
  return 0;
}

Compile and run the program. It will ask you for two numbers. Copy

  6456477721591 6456492967333
into the terminal and hit enter. Record the answer and save it into a file called answer.txt.


Submitting Your Work

Normally, you would not submit my work as your own, but this assignment is just to get you some experience to using Linux. In the directory that contains your work, run command

  ~abrahamsonk/3300/bin/submit 0 assn0.cpp answer.txt
You should get a reply that the submission was successful. See submitting assignments.