Sunday, March 23, 2014

Program of magic. magic.cpp

#include<iostream.h>
#include<conio.h>
int main()
{
   
    int i,ans=0;
    clrscr();
    cout<<"\nChoose one number in your mind from 1 to 63 \n";
    cout<<"\n1    3    5    7    9    11    13    15 \n";
    cout<<"\n17    19    21    23    25    27    29    31 \n";
    cout<<"\n33    35    37    39    41    43    45    47 \n";
    cout<<"\n49    51    53    55    57    59    61    63 \n";
    cout<<"Write 0 if number in your mind is present or else write 1 if not present\n";
    cin>>i;
    if(i==0)
    {
        ans=ans+1;
    }
    else
    {
        ans=ans;
    }


    cout<<"\n2    3    6    7    10    11    14    15 \n";
    cout<<"\n18    19    22    23    26    27    30    31 \n";
    cout<<"\n34    35    38    39    42    43    46    47 \n";
    cout<<"\n50    51    54    55    58    60    62    63 \n";
    cout<<"Write 0 if number in your mind is present or else write 1 if not present\n";
    cin>>i;
    if(i==0)
    {
        ans=ans+2;
    }
    else
    {ans=ans;}

    cout<<"\n4    5    6    7    12    13    14    15 \n";
    cout<<"\n20    21    22    23    28    29    30    31 \n";
    cout<<"\n36    37    38    39    44    45    46    47 \n";
    cout<<"\n52    53    54    55    60    61    62    63 \n";
    cout<<"Write 0 if number in your mind is present or else write 1 if not present\n";
    cin>>i;
    if(i==0)
    {
        ans=ans+4;
    }else
    {ans=ans;}
    cout<<"\n8    9    10    11    12    13    14    15 \n";
    cout<<"\n24    25    26    27    28    29    30    31 \n";
    cout<<"\n40    41    42    43    44    45    46    47 \n";
    cout<<"\n56    57    58    59    60    61    62    63 \n";
    cout<<"Write 0 if number in your mind is present or else write 1 if not present\n";
    cin>>i;
    if(i==0)
    {
        ans=ans+8;
    }else
    {ans=ans;}
    cout<<"\n16    17    18    19    20    21    22    23 \n";
    cout<<"\n24    25    26    27    28    29    30    31 \n";
    cout<<"\n48    49    50    51    52    53    54    55 \n";
    cout<<"\n56    57    58    59    60    61    62    63 \n";
    cout<<"Write 0 if number in your mind is present or else write 1 if not present\n";
    cin>>i;
    if(i==0)
    {
        ans=ans+16;
    }else
    {ans=ans;}

    cout<<"\n32    33    34    35    36    37    38    39 \n";
    cout<<"\n40    41    42    43    44    45    46    47 \n";
    cout<<"\n48    49    50    51    52    53    54    55 \n";
    cout<<"\n56    57    58    59    60    61    62    63 \n";
    cout<<"Write 0 if number in your mind is present or else write 1 if not present\n";
    cin>>i;
    if(i==0)
    {
        ans=ans+32;
    }else
    {ans=ans;}
    cout<<"The answer in your mind is : ";
    cout<<ans;
    getch();
    return 0;
}


Saturday, March 15, 2014

Program to find GCD of two numbers

#include<iostream.h>
int main()
{
int first_number,second_number,gcd,i;
cout<<"Enter First Number : ";
cin>>first_number;

cout<<"Enter Second Number: ";
cin>>second_number;

for(i=1;i<=first_number&&i<=second_number;i++)
{

     if(first_number%i==0 && second_number%i == 0 )
{
                     gcd=i;

    }

}

cout<<"Greatest Common Division (GCD):"<<gcd<<endl;
return 0;
}

******Output******
Enter First Number: 9
Enter Second Number: 24
Greatest Common Division (GCD):3 

What is GCD of two numbers?
 It means a greatest number which divides both numbers
For example: Two numbers are 9 and 24
Numbers which divides both are 1 and 3 in which greatest number is 3
So 3 is the GCD of 9 and 24

Click here for more programs on C++

Monday, March 3, 2014

Program in C++ to count heart beats of a person by its age from born

# include <iostream.h>
int main()
{
int age,heartbeats;
cout<<"Enter Age: ";
cin>>age;
cout<<"Enter Number of Heartbeats per min: ";
cin>>heartbeats;

heartbeats = heartbeats * 60; //heartbeats per hour

heartbeats = heartbeats * 24; //heartbeats per day

heartbeats = heartbeats * 365; //heartbeats per year

cout<<"Your Heart has beat "<<heartbeats * age<<" times since you were born."<<endl;

return 0;
}

-----------------------OUTPUT---------------------
 Enter Age: 26
 Enter Number of Heartbeats per min: 70
 Your Heart has beat  956592000  times since you were born.

Program in C++ for Fibonacci Series using recursion function

#include<iostream.h>
fibonacci(int);            //function prototype
void main()
{
int n,i,f;
cout<<"Enter the total elements in the series : ";
cin>>n;
cout<<"\nThe Fibonacci series is:\n";
for(i=0;i<n;i++)
    {
        f=fibonacci(i); //function call
        cout<<f<<"  ";
    }
}

fibonacci(int n)        //function definition
{
    int f;
    if(n==0)
    return 0;
    else if(n==1)
    return 1;
    else
    f=fibonacci(n-1)+fibonacci(n-2);  /*Two recursion function calling itself with different arguments.*/
    return f;
}

-----------------OUTPUT---------------

Enter the total elements in the series :  7
The Fibonacci series is:
0    1    1    2    3    5    8

Note: -When a function call itself within its body is known as recursion function .The function calling has different arguments.
Fibonacci Series means addition of previous two numbers example 0+1=1 , 1+1=2 , 1+2=3 ,2+3=5 , 3+5 =8 , and so on .So the Fibonacci Series is 0,1,1,2,3,5,8,13,21,34


Click here for more programs on C++

Saturday, March 1, 2014

Using power function display armstrong number

#include<iostream.h>
#include<math.h>
int main()
{
int sum,n,temp,rem;
cout<<"The Armstrong number between the range 1 to 500 are : \n"; 
for(int x=1;x<=500;x++)
{
n=x;
sum=0;
temp=n;
do
{
rem=n%10;
n=n/10;
int p;
p=pow(rem,3);
sum=sum+p;
}while(n!=0);
if(sum==temp)
cout<<x<<"\t";
}
cout<<"\t";
return 0;
}

Output:
The Armstrong number between the range 1 to 500 are : 
1      153     370     371     407
 

Program to dispaly armstrong number between 1 to 500

#include<iostream.h>
int main()
{
int sum,n,temp,rem;
cout<<"The Armstrong number between the range 1 to 500 are : \n"; 
for(int x=1;x<=500;x++)
{
n=x;
sum=0;
temp=n;
do
{
rem=n%10;
n=n/10;
sum=sum+rem*rem*rem;
}while(n!=0);
if(sum==temp)
cout<<x<<"\t";
}
cout<<"\t";
return 0;
}


Output:
 The Armstrong number between the range 1 to 500 are :
1        153         370       371        407

C++ Program to check whether number is Armstrong number

#include<iostream.h>
int main()
{
      int sum,temp,rem,n;
     cout<<"Enter the number \n";
     cin>>n;
     cout<<" Entered number is \t";
     cout<<n;
     cout<<"\n";
     sum=0; 
     temp=n;
      do
        {
                rem=n%10;
                n=n/10;
                sum=sum+rem*rem*rem;
           }while(n!=0);
     if(sum==temp)
            cout<<"This is Armstrong number.\n";
   else
           cout<<"This is not Armstrong number.\n";
return 0;
}

Output:-
Enter the number
371
Entered number is    371
This is Armstrong number.

Italian language alphabets pronunciation grammar phrases vocabulary

 The Italian alphabet consists of 21 letters, with a few additional letters used in foreign words. Here's the Italian alphabet: 1. A (a)...