Thursday, February 23, 2012

Program to find the prime numbers between 1 to 100

#include <iostream>
using namespace std;

int main()
{   
    int i,j;
    int s;
    for( i =1; i<=100; i++)
    {
        s=0;
        for( j=1; j<=i; j++)
        {
            if( i%j == 0)
            s = s+1;
        }
    
        if(s==2)
        {
            cout << "\n" << i;
        }
     }
 }

using a for loop to print Ten Non-Negative Numbers

#include <iostream>
using namespace std;

int main()
{
    for (int i=0; i!=10; i=i+1)
    cout << "\n" << i;
}


OUTOUT:
 

Friday, February 10, 2012

calculate all factor of a number

//program to calculate total no. of factor of a number
// factor of 10 is -- 1, 2, 5, 10 (total is 4)

#include<iostream>
using namespace std;

int main()
{
    int n, i, c=0;
   
    cout << "Enter the number: ";
    cin >> n;
    

    for(i=1;i<=n;i++)
    {
        if( n%i == 0)
        c++;
    }


    cout << "The number of factor of the number " << n << " is: " << c; 
}

Program to find out HCF and LCM

// find out hcf and lcm
// using c


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

int main()
{
    int a, b, x, y, t, gcd, lcm;
   
    printf ( "Enter two integers\n" );
    scanf ( "%d%d", &x, &y );
   
    a = x;
    b = y;
   
    while (b != 0)
    {
        t = b;
        b = a % b;
        a = t;
    }
   
    gcd = a;
    lcm = (x*y) / gcd;
   
    printf ( "greatest common divisor of %d and %d = %d\n", x, y, gcd );
    printf ( "least common multiple of %d and %d = %d\n", x, y, lcm );
}

Program for checking palindrome number

//Program to check palindrome number
// using c


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

int main()
{
    int n, reverse = 0, temp;
    printf ( "Enter a number to check if it is a palindrome or not\n" );
    scanf ( "%d", &n );
   
    temp = n;
    while ( temp != 0 )
    {
        reverse = reverse * 10;
        reverse = reverse + temp%10;
        temp = temp/10;
    }
   
    if (n == reverse)
    {
        printf ( "%d is a palindrome number.\n", n);
    }
    else
    {
        printf ( "%d is not a palidrome number.\n", n);
    }
}

Wednesday, February 8, 2012

The list of 'keyword' you must known

  1. friend -- Grant non-member function access to private data.
  2. inline -- Optimize calls to short functions.
  3. namespace -- Partition the global namespace by defining a scope.
  4. new -- Allocate dynamic memory for a new variable.
  5. static -- Create permanent storage of a variable.
  6. template -- Create generics functions.
  7. this -- A pointer to the current object.
  8. using -- Import complete or partial namespace.
  9. virtual -- Create a function that can be overridden by a derived class.