Pages

Write a program to check whether the given number is palindrome or not?

Friday 21 February 2014

Note: Polindrome is a number that is same if we reverse it. e.g: 151 reverse is 151



#include <iostream>
using namespace std;

int main()
{
    int number, ans = 0, temp;
    cout << "Enter a number: ";
    cin >> number;
    temp = number;
    while( number != 0)
    {
           ans = ans*10;
           ans = ans + number%10;
           number = number/10;
    }
    if(ans == temp)
    {
           cout << "Number is polindrome.";
    }
    else
    {
           cout << "Number is not polindrome.";
    }
    system("pause");
}

Write a program in C++ to print Pascal Series on screen



#include <stdio.h>
#include <conio.h>

long factorial(int);

int main()
{
   int i, n, c;

   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);

   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
         printf(" ");

      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));

      printf("\n");
   }

   getch();
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
         result = result*c;

   return ( result );
}

Write a program to find GCD and LCM in C++ language

#include <iostream>
using namespace std;

int main()
{
    int a, b, temp, gcd, lcm, x, y;
    cout << "Enter two number: ";
    cin >> x>>y;
   
    a = x;
    b = y;
   
    while(b!= 0)
    {
           temp = b;
           b = a%b;
           a = temp;
    }
   
    gcd = a;
    lcm = x*y/gcd;
   
    cout << "GCD is: "<<gcd<<"\nLCM is: "<<lcm<<endl;
    system("pause");
}

Write a program to find first 1000 armstrong numbers in C++ language

Note: Armstrong numbers are those numbers if we take cube of their digits individually and add them then it will equal to the number.
e.g: 153
1^3 + 5^3 + 3^3 = 153



#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int remainder, temp, sum=0, num, i;
for(i=1; i<=1000; i++)
{
    num = temp = i;
    sum = 0;
    while(temp != 0)
    {
          remainder = temp%10;
          sum = sum + remainder*remainder*remainder;
          temp = temp/10;
    }
    if(num == sum)
           cout <<sum<<endl;
}
    getch();
}

Write a program in C++ to find angle between minutes and second hand, hour and second hand and hour and minute hand.

#include <iostream>
using namespace std;

int main()
{
    int hour, minut, second, angle1, angle2, angle;
    cout << "Enter hour: ";
    cin >> hour;
    cout << "Enter minut: ";
    cin >> minut;
    cout << "Enter second: ";
    cin >> second;
   
    //angle between hour and minut.
    if(angle1 == 12)
    angle1 = 0;
   
    angle1 = hour*30;
    angle2 = minut*6;
 
    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and minut is: ";
    cout << angle << endl;
   
    //angle between hour and second.
    if(angle1 == 12)
    angle1 = 0;
   
    angle1 = hour*30;
    angle2 = second*6;

    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and second is: ";
    cout << angle << endl;
   
    //angle between hour and second.
    angle1 = minut*6;
    angle2 = second*6;

    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and second is: ";
    cout << angle << endl;
   
    cout <<endl;
    system("pause");
}

Write a program to add two numbers by using pointers in C++ language.

#include <iostream>
using namespace std;

int main()
{
    int a, b, *p1, *p2, sum;
    cout << "Enter both numbers: ";
    cin >> a >> b;
    p1 = &a;
    p2 = &b;
    sum = *p1 + *p2;
    cout << "Sum is " << sum <<endl;
    system("pause");
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *