1 / 6

Example 21

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.";

ianthe
Download Presentation

Example 21

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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."; break; 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 <<" "; cout <<endl; for (i=0; i<=SIZE; i++) cout <<"_____"; for (i=0; i<=SIZE; i++) { cout <<endl <<setw(3) <<i <<" |"; for (j=1; j<=SIZE; j++) cout <<setw(3) <<i*j <<" "; } cout <<endl; 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 <<endl; for (i=0; i<6; 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++) for (int j=0; j<6; j++) cout <<setw(12) <<array2[i][j]; cout <<endl <<endl; for (i=0; i<2; i++) for (int j=0; j<6; j++) cout <<setw(12) <<array3[i][j]; cout <<endl; return 0; }

More Related