Lab Assignment 3
CSE 1310
20110913 15:11:19
CSE 1310 – Laboratory Assignment #3
This assignment was written by Dr. Darin Brezeale & refined by Dr. Arthur Reyes.
Week of September 28, 2009
name:
Darin Brezeale
course:
CSE 1310
assignment:
lab 3a
date:
September 21, 2009
purpose:
1)
Practice using loops.
2)
Practice using conditionals.
description:
Write a program that for the integers in the range 2 to 100, counts how many
are evenly divisible by 2, 3, 5, or 7.
The program should print the counts when done.
sample output:
$ ./lab3a
There are 50 integers evenly divisible by 2
There are 33 integers evenly divisible by 3
There are 20 integers evenly divisible by 5
There are 14 integers evenly divisible by 7
CHECKPOINT: Show your source code to the TA.
CHECKPOINT: Let the TA run your program.
Solution:
#include <stdio.h>
int main (void)
{
int count1 = 0;
int count2 = 0;
int count3=0;
int count4 = 0;
int i;
for(i =2; i <= 100; i++)
{
if((i%2) == 0)
count1++;
if((i%3) == 0)
count2++;
Page 1 of 6
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Lab Assignment 3
CSE 1310
20110913 15:11:19
if((i%5) == 0)
count3++;
if((i%7) == 0)
count4++;
}
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '11
 DarinBrezeale
 Integers, TA, main (void), Darin Brezeale

Click to edit the document details