SQL

Wednesday, 21 May 2014

Separate integers, i.e 67890 will output 6 7 8 9 0

#include <iostream>
#include <iomanip>
using namespace std;

int quotient(int, int);
int reminder(int , int);
int main(){

int number;
int divisor = 10000;

cout << "ENter an integer between 1 - 32767 :";
cin >> number;

cout << "THe Digit in the number are :\n";

while (number >= 1){

if (number >= divisor){

cout << setw(3)<<quotient(number, divisor);
number = reminder(number, divisor);
divisor = quotient(divisor, 10);
}
else
divisor = quotient(divisor, 10);

}
cout << endl;
return 0;

}
int quotient(int a, int b){

return a / b;
}
int reminder(int a, int b){

return a % b;
}

Friday, 16 May 2014

Create Diamond C++

Excercise From C++ how to program

2.58 Write a program that prints the following diamond shape. You may use output statements that print either a single asterisk
(*) or a single blank. Maximize your use of repetition (with nested for structures) and minimize the number of output statements.

        *
      ***
    *****
  *******
*********
  *******
    *****
      ***
        *
#include 
using namespace std;
int main(){


 for (int row = 1; row <= 5; row++){
  for (int space = 1; space <= 5 - row; space++){

     cout << " ";

  }
  
  for (int asterisk = 1; asterisk <= 2 * row - 1; asterisk++){

   cout << "*";
   
  
  }

  cout << '\n';


 }


 for (int row = 4; row >=1; row--){
  for (int space = 1; space <= 5-row; space++){

   cout << " ";

  }

  for (int asterisk = 1; asterisk <=2 * row - 1; asterisk++){

   cout << "*";


  }

  cout << '\n';


 }
 cin.get();
 return 0;
}