Lab Zero Exercises

## First things first

1. Installing Dev C++
2. Hello World program in C++ with detailed explanation
3. 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()

1. Create array of integers and initialize them to zero Solution
2. Print the even numbers in an array Solution
3. Count the number of even numbers in an array Solution
4. Calculate the sum of all elements in an array Solution
5. Find the greatest and smallest numbers in an array
6. Write a function to return an array of all the odd numbers in a given array [Solution]

## Exercises for Week 2

1. 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]
2. 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
3. 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]
4. 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