Friday, 25 March 2016

c++ code to implement call by Reference.

#include<iostream.h>
#include<conio.h>
void add(int *,int *);



void main()
{
 clrscr();
 int a;
 int b;
 cout<<"Enter first no";
 cin>>a;
 cout<<"Enter Second no";
 cin>>b;
 add(&a,&b);
 cout<<"first no="<<a<<endl;
 cout<<"Second no="<<b;
 getch();
}


void add(int *x,int *y)
{
  int t;
  t=*x;
  *x=*y;
  *y=t;
}


Wednesday, 17 February 2016

c++ program to check stron no.

#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int n;
  int temp;
  cout<<"enter the no";
  cin>>n;
  temp=n;
  int sum=0;

  while(n)
   {
     int r=n%10;
     n=n/10;
    int sum1=1;
    for(int i=1;i<=r;i++)
    {
       sum1=sum1*i;
    }
   sum=sum+sum1;

  }

  if(sum==temp)
  {
   cout<<"No is strong";
  }
  else
  cout<<"No is not strong";
  getch();
}

c++ program to find factorial of a no.

#include<iostream.h>
#include<conio.h>

void main()
{
   int n;
   cout<<"Enter the no";
   cin>>n;
   int sum=1;
  for(int i=1;i<=n;i++)
  {
    sum= sum*i;
  }
  cout<<sum;
  getch();
}

c++ program to check Armstrong no.


#include<iostream.h>
#include<conio.h>

void main()
{
  clrscr();
  int n;
  int temp;
  int count=0;
  //int sum1=1;
  int sum=0;
  cout<<"enter the no";
  cin>>n;
  temp=n;
  int num;
  num=n;

 while(n)
  {
   n=n/10;
   count++;
  }

while(num)
 {
   int r=num%10;
   num=num/10;
   int sum1=1;
   for(int i=1;i<=count;i++)
   {
     sum1=sum1*r;
   }
  sum=sum+sum1;
 }

if(sum==temp)
cout<<" No is armstrong";
else
cout<<"No is not armstrong";
getch();
}

program to check palindrome no.

#include<iostream.h>
#include<conio.h>

void main()
{
  clrscr();
  int n;
  int temp;
  cout<<"enter the No";
  cin>>n;
  temp=n;
  int sum=0;

 while(n)//1 means true and 0 means false.
  {
    int r=n%10;
    n=n/10;
    sum=(sum*10)+r;
  }

if(sum==temp)
{
cout<<"No is palindrome";
}
else
cout<<"No is not palindrom";
getch();
}

c++ program to check perfect no.

#include<iostream.h>
#include<conio.h>

void main()
{
   clrscr();
   int n;
   int sum=0;
   cout<<"Enter the no"<<endl;
   cin>>n;
  for(int i=1;i<n;i++)
   {
     if(n%i==0)
     {
        sum=sum+i;
     }
  }
if(sum==n)
{
cout<<"No is perfect";
}
else
cout<<"No is not perfect";
getch();
}

c++ program to check prime no.

#include<iostream.h>
#include<conio.h>

void main()
 {
   int count=0;
   int p;
  cout<<"Enter the no";
  cin>>p;
  for(int i=1;i<=p;i++)
   {
      if(p%i==0)
     {
       count=count+1;
     }
  }
if(count==2)
{
 cout<<"No is prime";
}
else
cout<<"No is not prime";
}