Lab Zero Exercises

## First things first

- Installing Dev C++
- Hello World program in C++ with detailed explanation
- Sum two numbers using a function eample how to use a function and
*cin**see the code*

## Exercises and solutions for Week 1

*Note that for all programs given below except the first one write a function and call it from the main()*

- Create array of integers and initialize them to zero
*Solution* - Print the even numbers in an array
*Solution* - Count the number of even numbers in an array
*Solution* - Calculate the sum of all elements in an array
*Solution* - Find the greatest and smallest numbers in an array
- Write a function to return an array of all the odd numbers in a given array [
*Solution*]

## Exercises for Week 2

- Write a program to accept a number from the keyboard using
*cin*and print the square and cube of that number. Use two functions one for calculating and returning the square of the number and another function for calculating and returning the cube of the number. [Learn how to use*cin*, how to declare and use functions and how to pass values to a function] - Write a program to accept a number from the keyboard using
*cin*and print whether the number is a prime number or not. Use a function*isPrime(int)*which returns a*bool*. [Learn how to use booleans in C++, functions and logic]*Solution* - Write a function to print all the prime numbers between 2 and some given limit. You may read the given limit from the console using
*cin*or hard code into your*main()*. [Learn how to use loop, functions and logic] - Write a function
*int* generatePrimes(int limit)*to generate all the prime numbers between 2 and some given limit and return them as an array. Print all elements from array from*generatePrimes()*in the*main()*or pass to a*printArray()*function shown to you earlier (see week 1 exercises above).

page revision: 16, last edited: 29 Oct 2011 10:25