Easy C++ Code
This blog is very helpful for anyone . if u have new program then send me i will post its solution . rzainulabideen@gmail.com
Thursday, 11 September 2014
Wednesday, 10 September 2014
program to Making a multiplication table using while loop .......
Table with while loop
#include<iostream>
using namespace std;
int main()
{
int i=1,a,b;
cout<<"enter the number of table : ";
cin>>a;
cout<<"enter the lenght :";
cin>>b;
cout<<"\n";
while( i<=b )
{
cout<<"\t\t"<<a<<" * "<<i<<" = "<< i * a <<"\n";
i++;
}
return 0;
}
program to Making a multiplication table using for loop .......
Table with for loop
#include<iostream>
using namespace std;
int main()
{
int i=1,a,b;
cout<<"enter the number of table : ";
cin>>a;
cout<<"enter the lenght :";
cin>>b;
cout<<"\n";
for ( i = 1 ; i <= b ; i++ )
{
cout<<"\t\t"<<a<<" * "<<i<<" = "<< i * a <<"\n";
}
return 0;
}
Program of do while loop , display 1-10 number
/////// do while \\\\\\\
#include<iostream>
using namespace std;
int main()
{
int i=1,a;
cout<<"enter the number : ";
cin>>a;
do
{
cout<<"\t\t"<<i<<"\n";
i++;
}while( i<=a );
return 0;
}
Program of for loop , display 1-10 number
#include<iostream>
using namespace std;
int main()
{
int i=1,a;
cout<<"enter the number : ";
cin>>a;
for ( i = 1 ; i <= a; i++ )
{
cout<<"\t\t"<<i<<"\n";
}
return 0;
}
program of for loop , display 1 to n number and their square
#include<iostream>
using namespace std;
int main()
{
int i=1,a;
cout<<"enter the number : ";
cin>>a;
for ( i = 1 ; i <= a; i++ )
{
cout<<"\t|*__*|\t\t"<<i<<"\t\t"<<i*i<<"\t\t|*__*|\n";
}
return 0;
}
Monday, 8 September 2014
program to Making a multiplication table using do while loop .......
Table with do while
#include<iostream>
using namespace std;
int main()
{
int i=1,a,b;
cout<<"enter the number of table : ";
cin>>a;
cout<<"enter the lenght :";
cin>>b;
cout<<"\n";
do
{
cout<<"\t\t"<<a<<" * "<<i<<" = "<< i * a <<"\n";
i++;
}
while( i<=b );
return 0;
}
Saturday, 6 September 2014
program of while loop , 1 to n number with their square
#include<iostream>
using namespace std;
int main()
{
int i=1,a;
cout<<"enter the limit : ";
cin>>a;
while( i<=a )
{
cout<<"\t\t"<<i<<"\t\t"<<i*i<<"\n";
i++;
}
return 0;
}
program of while loop , display 1-10 number and their square
#include<iostream>
using namespace std;
int main()
{
int i=1;
while( i<=10 )
{
cout<<"\t\t"<<i<<"\t\t"<<i*i<<"\n";
i++;
}
return 0;
}
program of while loop , display 1-10 number
#include<iostream>
using namespace std;
int main()
{
int i=1;
while( i<=10 )
{
cout<<i<<"\n";
i++;
}
return 0;
}
program for finding factorial of a number
#include<iostream>
using namespace std;
int main()
{
int n,f = 1;
cout<<"Enter any number : ";
cin>>n;
while(n >= 1)
{
f = f * n;
n--;
}
cout<<"Factorial of number is "<<f;
return 0;
}
program of Global and local variables
- A local variable is a variable that is declared inside a function.
- A global variable is a variable that is declared outside ALL functions
#include<iostream>
using namespace std;
int A, B;
int Add()
{
return A + B;
}
int main()
{
int answer;
A = 2;
B = 2;
answer = Add();
cout << A << " + " << B << " = " << answer;
return 0;
}
Program to check for vowel or consonant using switch
// code is given below
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
char ch;
cout<<"Enter any character from A to Z \n\n";
cin>>ch;
switch(ch)
{
case 'A':
cout<<ch<<" is Vowel \n\n";
break;
case 'E':
cout<<ch<<" is Vowel \n\n";
break;
case 'I':
cout<<ch<<" is Vowel \n\n";
break;
case 'O':
cout<<ch<<" is Vowel \n\n";
break;
case 'U':
cout<<ch<<" is Vowel \n\n";
break;
case 'a':
cout<<ch<<" is Vowel \n\n";
break;
case 'e':
cout<<ch<<" is Vowel \n\n";
break;
case 'i':
cout<<ch<<" is Vowel \n\n";
break;
case 'o':
cout<<ch<<" is Vowel \n\n";
break;
case 'u':
cout<<ch<<" is Vowel \n\n";
break;
default:
cout<<ch<<" is Consonant \n\n";
}
return 0;
}
Program to Check Whether a character is Vowel or Consonant
// Code is given below
#include <iostream>
using namespace std;
int main()
{
char c;
cout << "Enter an alphabet :: ";
cin >> c;
if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U')
{
cout << c << " is a vowel.\n\n";
}
else
{
cout << c << " is not a vowel.\n\n";
}
return 0;
}
Tuesday, 2 September 2014
Program to find leap year
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int year;
cout<<"Enter the year : ";
cin>>year;
if( year % 4== 0)
{
cout<<"It is a leap year";
}
else
{
cout<<"It is not a leap year";
}
return 0;
}
Program foa calculating average of 5 number
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e,avg;
cout<<"enter the 1st number :";
cin>>a;
cout<<"enter the 2nd number :";
cin>>b;
cout<<"enter the 3rd number :";
cin>>c;
cout<<"enter the 4th number :";
cin>>d;
cout<<"enter the 5th number :";
cin>>e;
avg = ( a + b + c + d + e )/5;
cout<<"Average is = "<<avg<<"\n\n\n";
return 0;
}
Program for reversing the number
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int num , digit ;
cout<<" Please enter the three number digit = ";
cin>> num ;
digit = num % 10;
cout<<"\n\n---------\t"<<digit;
num = num / 10;
digit = num % 10;
cout<<digit;
num = num / 10;
digit = num % 10;
cout<<digit<<"\n\n";
return 0;
}
Program to check which number is greater
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int a , b;
cout<<" enter the 1st number = ";
cin>> a;
cout<<"enter the 2nd number = ";
cin>> b;
if ( a > b )
{
cout<<" greater number is "<< a<<"\n\n\n";
}
else if ( a < b )
{
cout<<" greater number is "<< b<<"\n\n\n";
}
else
cout<<" numbers are same \n\n\n ";
return 0;
}
Program for calculating area of square
// Code is given below
#include<iostream>
using namespace std;
int main()
{
float lenght , area ;
cout<<"Enter the lenght :";
cin>>lenght;
area = lenght * lenght ;
cout<<"Area of square is "<<area<<"\n\n\n";
return 0;
}
Program for finding cube of any number
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter the number :";
cin>>a;
b = a * a * a;
cout<<"cube of "<<a<<" is = "<<b<<"\n\n\n";
return 0;
}
Program for finding square of any number
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter the number :";
cin>>a;
b = a * a ;
cout<<"Sqaure of "<<a<<" is = "<<b<<"\n\n\n";
return 0;
}
Program for checking numbers are same or not
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int a ,b ;
cout<<" enter 1st number = ";
cin>> a;
cout<<" enter 2nd number = ";
cin>> b;
if ( a == b )
{
cout<<" numbers are same\n\n\n";
}
else
{
cout<<" number are different\n\n\n";
}
return 0;
}
program for checking even or odd
// Code is given below
#include<iostream>
using namespace std;
int main()
{
int a ;
cout<<" enter a number = ";
cin>> a;
if ( a % 2 == 0 )
{
cout<<" number is even\n\n\n";
}
else
{
cout<<"number is odd\n\n\n ";
}
return 0;
}
Program for checking +ve number or -ve number
// Code is given below
#include<iostream>
using namespace std;
int main()
{
float a;
cout<<"enter a number = ";
cin>> a;
if ( a > 0 )
{
cout<<"number is +ve\n\n\n";
}
else if( a < 0 )
{
cout<<"number is -ve\n\n\n";
}
else
{
cout<<"number is zero\n\n\n";
}
return 0;
}
Program for dividing two number
// Code is given below
#include<iostream>
using namespace std;
main()
{
int a,b,result;
cout<<"enter the first number : ";
cin>>a;
cout<<"enter the 2nd number : ";
cin>>b;
if ( a > b )
{
result = a / b ;
cout<<"a / b = "<<result<<"\n";
}
else
cout<<"Please enter the 1st number greater ";
return 0;
}
program for multiplying two number
for ( int ) data type
// Code is given below
#include<iostream>
using namespace std;
main()
{
int a,b,result;
cout<<"enter the first number : ";
cin>>a;
cout<<"enter the 2nd number : ";
cin>>b;
result = a * b ;
cout<<"a * b = "<<result<<"\n";
return 0;
}
// Code is given below
#include<iostream>
using namespace std;
main()
{
int a,b,result;
cout<<"enter the first number : ";
cin>>a;
cout<<"enter the 2nd number : ";
cin>>b;
result = a * b ;
cout<<"a * b = "<<result<<"\n";
return 0;
}
program for adding two value
// Code is given below
*********************************************************************************
#include<iostream>
using namespace std;
main()
{
int a,b,result;
cout<<"enter the first number : ";
cin>>a;
cout<<"enter the 2nd number : ";
cin>>b;
result = a + b ;
cout<<"a + b = "<<result<<"\n";
return 0;
}
Subscribe to:
Posts (Atom)