Posts

Showing posts from 2016

Program to determine the fatorial of a number using while loop.

Image
Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() { int n,factorial=1; cout<<"enter the integer="; cin>>n; while (n> 1) { factorial*=n--; } cout<<"\nFactorial="<<factorial; _getche(); } =========================================================================

Program to take square root of a number.

Using Visual Studio 2015 ============================================================== #include<iostream> using namespace std; #include<conio.h> #include<math.h> void main() { float num; cout<<"Enter number="; cin>>num; cout<<sqrt(num); _getche(); } ========================================================================= It's a simple program to take a square root of a number. For this program we take an additional header file '#include<math.h>'. We take a special keyword for this too 'sqrt' and then enter the number in the brackets.

Program to print day/month/year in C++

Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() { int day,month,year; cout<<"Day="; cin>>day; cout<<"Month="; cin>>month; cout<<"Year="; cin>>year; cout<<day<<"/"<<month<<"/"<<year; _getche(); } =========================================================================

Program to swap two numbers in C++

Using Visual Studio  2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() {   int a,b,c;   cout<<"A=";   cin>>a;   cout<<"B=";   cin>>b;   c=a;   a=b;   b=c;   cout<<"\nA="<<a;   cout<<"\nB="<<b;   _getche(); } ========================================================================= It is an easy program. First we take two input numbers from the user. Then we assign first number to the variable ' c '. Then we assign the value of 'b' to the variable ' a '. In this way, ' c ' has the value of 'a' and ' a ' has the value of 'b' . Then we assign the value of ' c ' (which was the value of ' a ') to ' b '. Then we store new values assigned to ' a ' and ' b ' using c

Program to find interest using if statement.

Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() { int input; label: cout <<"\nEnter current year="; cin>>input; input = input - 1991; cout<<"\nyears="; cout<<input; if (input >= 0) {   if (input >= 5)   {       input/=5;    input*=1000;    cout<<"\nThe interest is=";    cout<<input;   }   else   {   cout<<"\nerror";           }  }  else  {   cout<<"\nerror";   goto label;  } _getche(); } ========================================================================= It is a program to find interest of almost 25 years. You can change the amount of interest by doing some alterations in the formula. For example, " Input*=1200 ".

Program to determine the vowels through switch statement.

Using Visual Studio 2015 =========================================================================== #include<iostream> using namespace std; #include<conio.h> void main() { char letter; cout<<"enter a letter="; cin>>letter; switch (letter) { case 'a':   case 'A':   case 'e':   case 'E':  case 'i':  case 'I':  case 'o':   case 'O':   case 'u':   case 'U':   cout<<"\nYou have entered a vowel.";   break;   default:   cout<<"Invalid input";   break;  }  _getche(); } ========================================================================= To determine vowels is much easier through 'Switch statement' than 'if else if' . If you have any query, contact.

Program to calculate basic arithmetic operations.

Using Visual Studio 2015 =============================================================== #include<iostream> using namespace std; #include<conio.h> void main() {   char O;  float num1,num2,Multiplication,Addition,Subtraction,Division;   cout<<"enter First Number=";   cin>>num1;   cout<<"enter Second Number=";   cin>>num2;   cout<<"enter an operator=";   cin>>O;   switch (O)   {    case '+':    Addition=a+b;    cout<<"\nAddition="<<Addition;    break;    case '*':     Multiplication=a*b;    cout<<"\nMultiplication="<<Multiplication;    break;    case '/':    Division=a/b;    cout<<"\nDivision="<<Division;    break;    case '-':    Subtraction=a-b;    cout<<"\nSubtraction="<<Subtraction;    break;    default:    cout<<"\n

Determining the uppercase and lowercase vowels.

Using Visual Studio 2015. ========================================================================= #include<iostream> using namespace std; #include<conio.h> void main() { char input; cout<<"Input="; cin>>input; if (input == 'a' || input == 'e' || input == 'i' || input == 'o' || input == 'u') { cout<<"Lowercase Vowel"; } else if (input == 'A' || input == 'E' || input == 'I' || input == 'O' || input == 'U') { cout<<"Uppercase vowel"; } else { cout<<"Invalid input"; } _getche(); } ========================================================================= This program is to determine a lowercase or an uppercase vowel from the user's given input. We used "using namespace std;" because in the Visual studio, the header file "iostream" cannot be used without it. We use