Friday, April 16, 2010

Factorial of a Number

#include<iostream.h>
#include<conio.h>
 void main()
 {
 clrscr();
 int n,l,f;
 f=1;
 cout<<"\nenter no.";
 cin>>n;
 for(l=1;l<=n;l++)
 {
 f=f*l;
 }
 cout<<"\nfactorial no is"<<f;
 getch();
 }

Sum of even and odd numbers from 10 numbers

#include<iostream.h>
#include<conio.h>
 void main()
 {
 clrscr();
 int n,l,e,o;
 e=0;
 o=0;
 cout<<"enter 10 nos.";
 for(l=1;l<=10;l++)
 {
 cin>>n;
 if(n%2==0)
 e=e+n;
 else
 o=o+n;
 }
 cout<<"sum of even nos."<<e;
 cout<<"sum of odd nos."<<o;
 getch();
 }

Count Even/Odd Numbers

#include<iostream.h>
#include<conio.h>
 void main()
 {
 clrscr();
 int l,n,e,o;
 e=0;
 o=0;
 cout<<"enter 10 nos.";
 for(l=1;l<=10;l++)
 {
 cin>>n;
 if(n%2==0)
 e=e+1;
 else
 o=o+1;
 }
 cout<<"\neven nos. are"<<e;
 cout<<"\nodd nos. are"<<o;
 getch();
 }

Biggest out of 10

#include<iostream.h>
#include<conio.h>
 void main()
 {
 clrscr();
 int num,n,a=0;
 cout<<"enter 10 nos.";
 for(num=1;num<=10;num++)
 {
 cin>>n;
 if(a<n)
 {
 a=n;
 }
 }
 cout<<"biggest no. is"<<a;
 getch();
 }

Biggest Out of 3

#include<iostream.h>
#include<conio.h>
 void main()
 {
 clrscr();
 int a,b,c;
 cout<<"enter 1st no\n";
 cin>>a;
 cout<<"enter 2nd no\n";
 cin>>b;
 cout<<"enter 3rd no\n";
 cin>>c;
 if(a>b)
 if(a>c)
 cout<<"a is bigger\n";
 else
 cout<<"c is bigger\n";
 else if(b>c)
 cout<<"b is bigger\n";
 else
 cout<<"c is bigger";
 getch();
 }

Bigger Number

void main()
{
clrscr();
int a,b;
cout<<"enter 1st no\n"; cin>>a;
cout<<"enter 2nd no\n"; cin>>b;
if(a>b)
cout<<"a is bigger\n"; if(b>a)
cout<<"b is bigger";
getch();
}

First 20 Odd Numbers

#include<iostream.h>
#include<conio.h>
 void main()
 {
 clrscr();
 int l;
 cout<<"1st 20 odd nos.";
 for(l=1;l<=40;l++)
 if(l%2!=0)
 cout<<"\n"<<l;
 getch();
 }