> value; factorial = 1; for (int i=2; i<=value; i++) factorial *=i; cout <<"Factorial " <>indicator; } while ((indicator == 'y')|| (indicator == 'y')); return 0; }"> > value; factorial = 1; for (int i=2; i<=value; i++) factorial *=i; cout <<"Factorial " <>indicator; } while ((indicator == 'y')|| (indicator == 'y')); return 0; }">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example 21 #include<iostream.h> int main() { char Letter = 0;

Similar presentations


Presentation on theme: "Example 21 #include<iostream.h> int main() { char Letter = 0;"— Presentation transcript:

1 Example 21 #include<iostream.h> int main() { char Letter = 0;
cout <<"Enter a lower case letter: "; cin >> Letter; switch (Letter * (Letter>='a' && Letter <= 'z')) case 'a': case 'e': case 'i': case 'o': case 'u': cout <<endl <<"You have entered a vowel."; break; case 0: cout <<endl << Letter <<" it is not a lower case letter."; default: cout <<endl <<"You entered a consonant." ; } cout <<endl; return 0;

2 Example 22 #include<iostream.h> int main() {
char indicator ='n'; long value =0, factorial = 0; do cout <<"Enter an integer value: "; cin >> value; factorial = 1; for (int i=2; i<=value; i++) factorial *=i; cout <<"Factorial " <<value <<" is " <<factorial; cout <<endl <<"Do you want to enter another value (y or n)?"; cin >>indicator; } while ((indicator == 'y')|| (indicator == 'y')); return 0; }

3 Example 23 #include<iostream.h> #include<iomanip.h>
int main() { int SIZE =9; int i=0, j=0; cout <<SIZE <<" by " <<SIZE <<"multiplication table"; cout <<endl; cout <<endl <<" |"; for (i=1; i<=SIZE; i++) cout <<setw(3) <<i <<" "; for (i=0; i<=SIZE; i++) cout <<"_____"; cout <<endl <<setw(3) <<i <<" |"; for (j=1; j<=SIZE; j++) cout <<setw(3) <<i*j <<" "; } return 0;

4 Arrays An array is simply a number of memory locations, each of which can store an item of data of the same data type and which are all referenced through the same variable name. Type name[size] Type name[row][column]

5 Example 24 #include <iostream.h> #include <iomanip.h>
int main() { int array1[6]={1, 2, 3 ,4, 5, 6}; int array2[6]={1, 2, 3}; int array3[6]; for (int i=0; i<6; i++) cout <<setw(12) <<array1[i]; cout <<endl; for (i=0; i<6; i++) cout <<setw(12) <<array2[i]; cout <<setw(12) <<array3[i]; cout <<endl; return 0; }

6 Example 25 #include <iostream.h> #include <iomanip.h>
int main() { int array1[2][6]={ {1, 2, 3 ,4, 5, 6}, {6, 5, 4, 3, 2, 1} }; int array2[2][6]={ {1, 2, 3}, {4, 3, 2, 1} int array3[2][6]={0}; for (int i=0; i<2; i++) for (int j=0; j<6; j++) cout <<setw(12) <<array1[i][j]; cout << endl <<endl; for (i=0; i<2; i++) cout <<setw(12) <<array2[i][j]; cout <<endl <<endl; cout <<setw(12) <<array3[i][j]; cout <<endl; return 0; }


Download ppt "Example 21 #include<iostream.h> int main() { char Letter = 0;"

Similar presentations


Ads by Google