CSC 101 Lecture Notes Week 1
Introduction to the Course
Introduction to Programming and Problem Solving
Relevant Reading: Chapters 1 and 2
PROGRAM INSTRUCTIONS: EXPLANATORY COMMENTS:
begin Begin the program let x be an integer variable Declare a variable to hold the input read x Read the number typed on the screen if x > 0 then Check if the number is > 0 (i.e., positive) print "yes" If so, print "yes" on the screen else If not, print "no" print "no" on the screen end End the program
#include <stdio.h> /* The C input/output library */ int main() { /* C programs always start with this header */ int x; /* Declare a variable to hold the input number */ scanf("%d", &x); /* Input the number typed on the screen */ if (x > 0) /* Check if the number is > 0 (i.e., positive) */ printf("yes"); /* If so, output "yes" to the screen */ else /* If not, */ printf("no"); /* output "no" to the screen */ } /* End of main program (matches the "{") */