Pages

Showing posts with label GENRAL PROGRAM. Show all posts
Showing posts with label GENRAL PROGRAM. Show all posts

Friday, 18 March 2011

PROGRAM OF FIBONACCI SERIES

DESCRIPTION-:This program display the Fibonacci series.A fibonacci series is one in which first term is 0 and second term is 1 and the next term is the sum of the two previous term and so-on.
This program display the Fibonacci series according to the users requirement OR upto user entered number.
FOR EXAMPLE-: If the user enter a number 5

then it generate fibonacci series as------
                        0    1    1    2    3    5    8

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,first=0,second=1,third;
cout<<"how many no u want to print";
cin>>n;
cout<<"fibonacci series"<<"\n";
cout<<first<<" "<<second<<"\n";
for(i=2;i<=n;i++)
{
third=first+second;
cout<<third<<"\n";
first=second;
second=third;
}
getch();

}

PROGRAM TO PRINT TABLE

DESCRIPTION-:This program print the table of the number entered by the user.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int i,n;
cout<<"Enter to print table of given no";
cin>>n;
cout<<"the table of given number is"<<"\n";
for(i=1;i<=10;i++)
cout<<"\t\t"<<n<<"*"<<i<<"="<<n*i<<"\n";
getch();
}

PROGRAM TO CONVERT TEMPERATURE

DESCRIPTION-:This program convert the temperature from Fahrenheit to the Celsius OR vice-versa according to the user need.
PROGRAM-:   
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int choice;
float temp,conv;
cout<<"temperature conversion menu"<<"\n";
cout<<"1.fahrenheit to celsius"<<"\n";
cout<<"2.celsius to fahrenheit"<<"\n";
cout<<"enter ur choice(1-2)";
cin>>choice;
if(choice==1)
{
cout<<"enter temp. in fahrenheit";
cin>>temp;
conv=(temp-32)/1.8;
cout<<"temp in celsius";
cout<<conv;
}
else
{
cout<<"enter temp. in celsius";
cin>>temp;
conv=(1.8*temp)+32;
cout<<conv;
}
getch();
}

PROGRAM TO FIND THE LARGEST NUMBER USING IF STATEMENT

DESCRIPTION-:This program accepts three numbers as input and then calculate the largest number between the three number using the if statement and at last it display that largest number.
FOR EXAMPLE-: If we entered three number as-------
                                  23       45      99
 Then program generates output s---------
 largest number is     99
 
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int max,a,b,c;
cout<<"enter three numbers:";
cin>>a>>b>>c;
max=a;
if(b>max)
max=b;
if(c>max)
max=c;
cout<<"the largest  of " <<a<<", "<<b<<" and "<<c<<" is " <<max;
getch();
}

PROGRAM FOR SWITCH STATEMENT

COMMENT-:THIS PROGRAM FINDS THE ADDITION,MULTIPLICATION,DIVISION,
SUBTRACTION OF TWO NUMBER USING THE SWITCH STATEMENT
DEPENDING UPON THE CHOICE OF THE USER    
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"enter the value of two numbers";
cin>>a>>b;
cout<<"1.addition"<<"\n";
cout<<"2.multiplication"<<"\n";
cout<<"3.division"<<"\n";
cout<<"4.subtraction"<<"\n";
int choice;
cout<<"enter your choice";
cin>>choice;
switch(choice)
{
case 1:c=a+b;
cout<<"sum is"<<c;
break;
case 2:c=a*b;
cout<<"multiplication is"<<c;
break;
case 3:c=a/b;
cout<<"division is"<<c;
break;
case 4:c=a-b;
cout<<"subtraction is"<<c;
break;
default:cout<<"invalid choice:";
}
getch();
}

PROGRAM TO CALCULATE THE SQUAREROOT OF THE GIVEN NUMBER

DESCRIPTION-:This program calculates the square root of the entered number.It may be sure that the value of entered number should be greater than the 0.As the value of square root for negative number is "imaginary".
FOR EXAMPLE-: If we enter element as------------
                                            64
 Then program generate output-------------
                  square root=8
 
PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a;
float squareroot,cuberoot;
cout<<"enter the number";
cin>>a;
cout<<"\n"<<"square root of the number is"   ;
squareroot=sqrt(a);
cout<<squareroot;
getch();
}

PROGRAM TO CALCULATE SQUARE AND CUBE OF A NUMBER

COMMENT-:THIS PROGRAM DISPLAY THE SQUARE,CUBE
OF THE NUMBERS
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,square,cube;
cout<<"enter the value of n";
cin>>n;
cout<<"cube and square of number is"<<"\n";
for(i=1;i<=n;i++)
{
square=i*i;
cube=i*i*i;
cout<<"\t\t"<<i<<"\t\t"<<square<<"\t\t"<<cube<<"\n";
}
getch();
}

PROGRAM TO CALCULATE THE SIMPLE INTEREST

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float p,r,t,si;
cout<<"enter principle,rate,interest";
cin>>p>>r>>t;
si=(p*r*t)/100;
cout<<"simple interest is"<<si;
getch();
}

PROGRAM TO FIND THE SUM OF TWO NUMBER

DESCRIPTION-:THIS PROGRAM FINDS THE SUM OF TWO NUMBERS
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<"enter the value of two numbers";
cin>>a>>b;
c=a+b;
cout<<"sum of two number is"<<c;
getch();
}

PROGRAM TO CALCULATE THE SUM OF DIGIT OF NUMBER

DESCRIPTION-:THIS PROGRAM FINDS THE SUM OF THE DIGITS
OF THE ENTERED NUMBER.
FOR EXAMPLE IF WE HAVE NUMBER 123
THEN SUM=1+2+3=6.  
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,rem,sum=0;
cout<<"enter the value of n";
cin>>n;
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
cout<<"sum of digit is"<<sum;
getch();
}

PROGRAM TO FIND THE ROOTS OF QUADRATIC EQUATION

DESCRIPTION-:THIS PROGRAM FINDS THE ROOT OF THE QUADRATIC EQUATION
Ax^2+Bx+C
IN THIS PROGRAM WE FIRST CALCULATE THE VALUE OF "D" FOR QUADRATIC EQUATION
IF THE VALUE OF D>0 THEN THE ROOTS ARE REAL AND HAVE DIFFERENT VALUE.
IF THE VALUE OF D=0 THEN BOTH THE ROOTS HAVE SAME VALUE.
 IF THE VALUE OF D<0 THEN THE ROOTS HAVE IMAGINARY VALUE.
PROGRAM-:
#include<iostream.h>
#include<math.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,x1,x2;
float d;
cout<<"enter the value of a,b,c"<<"\n";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
if(d==0)
{
x1=x2=(-b)/(2*a);
cout<<"roots are real and value is"<<x1<<"\n";
}
else if(d>0)
{
x1=(-b)+sqrt(d)/(2*a);
x1=(-b)-sqrt(d)/(2*a);
cout<<"the value of two roots are"<<"\n";
cout<<"x1="<<x1<<"\n"<<"x2="<<x2;
}
else
{
cout<<"roots are imaginary";
}
getch();
}

PRIME NUMBER PROGRAM

DESCRIPTION-:THIS PROGRAM IS USED TO CHECK WHETHER THE ENTERED
NUMBER IS PRIME OR NOT.
A PRIME NUMBER IS ONE WHICH IS NOT DIVISIBLE BY ANY OTHER
NUMBER EXCEPT ITSELF .FOR EXAMPLE 5,43,23,17.......
PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int n;
char ch;
do
{

cout<<"enter the number";
cin>>n;

for (int i=2;i<=n/2;i++)
{
if(n%i==0)
{
cout<<"no is not prime";
goto start;
}
}
cout<<"no is prime";
start:
cout<<"u waana further continue(Y/y)";
cin>>ch;
}
while(ch=='y'||ch=='Y');
getch();
}

PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS PALINDROME OR NOT

DESCRIPTION-:THIS PROGRAM CHECKS WHETHER THE ENTERED NUMBER IS PALINDROME
OR NOT.PALINDROME NUMBER IS ONE WHOSE REVERSE IS SAME AS THAT
OF ENTERED GIVEN NUMBER.NOT
THIS PROGRAM FIRST CALCULATE THE REVERSE OF THE GIVEN NUMBER AND THEN CHECK WHETHER THE REVERSE OF NUMBER IS EQUAL TO THE ENTERED NUMBER,IF BOTH NUMBERS ARE SAME THEN THE ENTERED NUMBER IS PALINDROME ELSE.
FOR EXAMPLE-: IF WE ENTER ELEMENT AS--------
                                       123
 THEN IT GENERATE OUTPUT AS---------
          THE NUMBER IS NOT PALINDROME
 
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,m,i,rem,rev=0;
cout<<"enter the required number";
cin>>n;
m=n;
while(m>0)
{
rem=m%10;
m=m/10;
rev=rev*10+rem;
}
cout<<"reverse of number is"<<rev<<"\n";
if(rev==n)
{
cout<<"number is palindrome";
}
else
{
cout<<"number is not palindrome";
}
getch();
}

PROGRAM TO CONVERT LOWERCASE LETTER TO UPPERCASE

DESCRIPTION-:THIS PROGRAM CONVERT A LOWERCASE LETTER INTO
UPPERCASE LETTER.
FOR EXAMPLE-: IF WE ENTER INPUT LOWERCASE  LETTER AS------------
                                            r
THEN IT GENERATES OUTPUT AS-----------
                      THE UPPERCASE EQUIVALENT=R

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
cout<<"enter the lowercase character"<<"\n";
cin>>ch;
char ch2=(ch>='a'&&ch<='z')?('A'+ch-'a'):ch;
cout<<"uppercase equivalent is   "<<ch2;
getch();
}

PROGRAM TO FIND LEAP YEAR

DESCRIPTION-:THIS PROGRAM CHECKS WHETHER THE
ENTERED YEAR IS LEAP OR NOT
PROGRAM-:

#include<iostream.h>
#include<conio.h>
void main()
{
int n;
cout<<"enter the year";
cin>>n;
if(n%4==0)
{
cout<<"entered year is leap year";
}
else
{
cout<<"the entered year is not leap year";
}
getch();
}

PROGRAM TO INTERCHANGE TWO NUMBERS

DESCRIPTION-:THIS PROGRAM INTERCHANGE THE TWO NUMBER WITHOUT USING THE THIRD VARIABLE.THIS PROGRAM ACCEPT TWO NUMBERS AS INPUT AND GENERATE TWO NUMBER IN OUTPUT BY SWAPPING THEIR VALUES.
PROGRAM-: 
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"enter  the value of a and b";
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\n"<<"after interchanging value of"<<"a="<<a<<"\n"<<"b="<<b;
getch();
}

GREATER BETWEEN THREE NUMBERS USING TERNARY OPERATOR

DESCRIPTION-:THIS PROGRAM FINDS GREATER BETWEEN THREE NUMBERS WITH
THE HELP OF TERNARY OPERATOR .
SYNTAX FOR TERNARY OPERATOR IS-:
EXPRESSION 1?EXPRESSION 2:EXPRESSION 3;
TERNARY  OPERATOR IS ONE IN WHICH IF THE CONDITION IS TRUE(i.e EXPRESSION 1) THEN IT EXECUTE EXPRESSION 2, ELSE IT EXECUTE EXPRESSION 3.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"enter three no.";
cin>>a>>b>>c;
d=((a>b&&a>c)?a:(b>a&&b>c)?b:c);
cout<<"greater no is"<<d;
getch();
}
DESCRIPTION-:THIS PROGRAM FINDS THE FACTORIAL OF THE GIVEN NUMBER
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,fact=1;
cout<<"enter the no. whose factorial is to be find";
cin>>n;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
cout<<"factorial of number is"<<fact;
getch();
}

PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS EVEN OR ODD

DESCRIPTION-:THIS PROGRAM CHECKS WHETHER THE GIVEN NUMBER IS
EVEN OR ODD
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"enter any number";
cin>>n;
if(n%2==0)
{
cout<<"number is even";
}
else
{
cout<<"number is odd";
}
getch();
}

PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS ARMSTRONG OR NOT

DESCRIPTION-: THIS PROGRAM FINDS THE ARMSTRONG NUMBER.
ARMSTRONG NUMBER IS ONE IN WHICH THE SUM
OF THE CUBES OF THE DIGITS IS EQUAL TO THE
NUMBER ITSELF.
FOR EXAMPLE 153
1^3+5^3+3^3=153       


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,m,rem,sum=0;
cout<<"enter the required number";
cin>>n;
m=n;
while(m>0)
{
rem=m%10;
m=m/10;
sum=sum+rem*rem*rem;
}
if(sum==n)
{
cout<<"number is armstrong";
}
else
{
cout<<"number is not armstrong";
}
getch();
}
 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.