logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/cs256su21code/jun01/count3.c

/*

similar to count2.c but demonstrates the modulus operator.

here, if the number is even, we print the word "even" instead of the 
number itself

*/

#include <stdio.h>

int main()
{
	int num = 1;


	while(num <= 10){

	/* 
	   the modulus operator will tell us what the remainder would be 
	   if we divided two numbers together. here, we want even numbers,
	   and all even numbers are divisible by 2, so we want numbers where 
	   that number mod 2 equals 0.
	*/ 
		if(num % 2 == 0){
			printf("even\n");
		}
		else{
			printf("%d\n", num);
		}
		
		num++;
	}


	return 0;
}