Session - C+ Overview Session 3 Alireza Abedinejad C+...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Overview Session 3 Alireza Abedinejad
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ Overview Selection Sort Factorial  Swap  Linear search  Search in a Table using linear search
Background image of page 2
Selection Sort #include <iostream> #include <time.h> // for using srand() and rand() functions using namespace std; void main() { int A[100]; // an array of integer with 100 elements int i, j; // Fill the array with random integers less than 10 // Seed the random-number generator with current time so that // the numbers will be different every time we run. srand( (unsigned)time( NULL ) ); for (i = 0; i < 100; i++) A[i] = rand() % 10;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Selection Sort, cont`d for (i = 0; i < 99; i++) { // find index of the minimum among A[i]. .A[n] int min_index = i; for (j = i+1; j < 100; j++) if (A[j] < A[min_index]) min_index = j; // swap A[i] and A[min_index] int min = A[min_index]; A[min_index] = A[i]; A[i] = min; } // for i for (i = 0; i < 100; i++) cout << A[i] << endl; }
Background image of page 4
#include <iostream.h> int fact( int n) { int f = 1, i; for
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

Session - C+ Overview Session 3 Alireza Abedinejad C+...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online