COSC 1320 Lecture Notes - Lecture 1: Pseudocode

29 views2 pages
30 Aug 2016
School
Course
Professor
Page:
of 2
Lecture 1;//Intro to programming
//Write a program to read 2 numbers. Compare them and print the smallest
//1 - 2 input variables and I output, type integer
//Initialize and read from the keyboard the 2 inputs...output variable is 0
//Compare if 1st < 2nd - 1st is smallest otherwise the second is smallest
//Print...The smallest number is 1st and the second is....
#include <iostream>
using namespace std;
//this program is to compare 2 numbers and print the smallest
int main(){
//1-declaration
int nb1;
int nb2;//don’t forget the semi colons after each statement
//2 initialize
cout<< "Enter the first Number\n";
cin>>nb1;
cout<< "Enter the second number\n";
cin>>nb2;
//3-process, comparison
if (nb1 < nb2)
cout<< " the smallest is " << nb1 <<endl;
else if(nb1 < nb2)
cout<< " the smallest is " << nb2 <<endl;
else
cout<< "the numbers are equal";
}
find more resources at oneclass.com
find more resources at oneclass.com
When asked to program always pseudocode; that is write it down in plain English on paper before
writing in code. Use the 4 steps. Declare, Initialize, Process, Print
find more resources at oneclass.com
find more resources at oneclass.com