Tuesday, July 29, 2014
Friday, July 11, 2014
Fibonacci Series
#include<iostream.h>
#include<conio.h>
void main()
{
int a=0,b=1,c=0,n;
clrscr();
cout<<"Enter the limit:";
cin>>n;
cout<<a<<"\n"<<b<<;
while(c<=n)
{
c=a+b;
if(c>n);
break;
a=b;
b=c;
}
getch();
}
Monday, July 7, 2014
Factorial Using Recursion
#include<iostream.h>
#include<conio.h>
void main()
{
int n,fact;
int rec(int); clrscr();
cout<<"Enter the number:";
cin>>n;
fact=rec(n);
cout<<endl<<"Factorial Result are<<fact<<"\n";
getch();
}
rec(int x)
{
int f;
if(x==1)
return(x);
else
{
f=x*rec(x-1);
return(f);
}
}
Tuesday, July 1, 2014
To find Prime or not
#include<iostream.h>
#include<conio.h>
void main()
{
int n,a=0;
clrscr();
cout<<"Enter the no:";
cin>>n;
for(int i=1;i<=n;i++)
{
if(n%i==0)
{
a++;
}
}
if(a==2)
cout<<"It's a prime number";
else
cout<<"It's not a prime no";
getch();
}
To print even numbers for a limit
To print even numbers for a limit
#include<iostream.h>
#include<conio.h>
void main()
{
int n;
clrscr();
cout<<"Enter your limit:";
cin>>n;
for(int=2;i<=n;i++)
{
if(i%2==0)
cout<<i<<"\n";
}
getch();
}
To print odd numbers for a limit#include<iostream.h>
#include<conio.h>
void main()
{
int n;
clrscr();
cout<<"Enter your limit:";
cin>>n;
for(int=1;i<=n;i++)
{
if(i%2==1)
cout<<i<<"\n";
}
getch();
}
To find largest in two/three no.s
To find largest in two no.s
#include <iostream.h>
#include <conio.h>
void main ()
{
int a,b;
clrscr ();
cout <<"Enter A: ";
cin >>a;
cout <<"Enter B: ";
cin >>b;
if (a>b)
{
cout <<"A is Greater";
}
else
{
cout <<"B is Greater";
}
getch ();
}
To find largest in three no.s
#include <iostream.h>
#include <conio.h>
void main ()
{
int a,b,c;
cout<<"Enter three no.s:";
cin>>a>>b>>c;
if(a>b)
{
if(a>c)
cout<<a<<"is greater";
else
cout<<c<<"is greater";
}
else
{
if(b>c)
cout<<b<<"is greater";
else
cout<<c<<"is greater";
}
getch();
}
To print 1 to 10 (using for loop)(c++)
To print 1 to 10
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=10;i++)
cout<<i<<endl;
getch();
return 0;
}
To print 1 to a limit
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i;
cout<<"Enter the limit:";
cin>>n;
for(i=1;i<=n;i++)
cout<<i;
getch();
}
Program for Summation,Subtraction,Multiplication,Average
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int a,b,sum,sub,mult,avg;
cin>>a>>b;
sum=a+b;
sub=a-b;
mult=a*b;
avg=(a+b)/2;
cout<<sum<<sub<<mult<<avg;
getch();
}
#include<conio.h>
int main()
{
clrscr();
int a,b,sum,sub,mult,avg;
cin>>a>>b;
sum=a+b;
sub=a-b;
mult=a*b;
avg=(a+b)/2;
cout<<sum<<sub<<mult<<avg;
getch();
}
Program to display ASCII code of a character and vise versa.
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
char ch='A';
int num=ch;
cout<<"The ASCII code for "<<ch<<"is"<<num<<"\n";
cout<<"Adding 1 to the character code: \n";
ch=ch+1;
num=ch;
cout<<"The ASCII code for"<<ch<<"is"<<num<<"\n";
return 0;
}
Output:-
The ASCII code for A is 65
Adding 1 to the character code :
The ASCII code for B is 66
A very simple program for printing a string.
#include<iostream.h>
#include<conio.h>
void main(){
cout<<"Welcome";
getch();
}
Output:-
Welcome
Subscribe to:
Comments (Atom)

