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

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

C++ Overview Session 3 Alireza Abedinejad

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

View Full Document
C++ Overview Selection Sort Factorial  Swap  Linear search  Search in a Table using linear search
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;

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

View Full Document
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; }
#include <iostream.h> int fact( int n) { int f = 1, i; for

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## 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
Ask a homework question - tutors are online