Sep 27, 2011

A set of simple programs written by C + + programming language

1-multiplier (using the idea of ​​recursion):

#include <iostream.h>
#include <conio.h>
int fact (int);
void main ()
{
int y;
cout << "Enter number: ";
cin >> y;
cout << "fact= " << fact(y);
getch();
}
int fact (int y)
{
if (y>1)
y = y * fact(y-1);
else
y=1;
return y;
}





2 - multiplier (without recursion):


#include <iostream.h>
#include <conio.h>
void main ()
{
int c,n,f=1;
cout << "Enter number: ";
cin >> n;
if (n>0)
{for (c=1; c<=n; c++)
f=f*c;
cout << "fact= " << f;}
else if (n == 0)
cout << "factorial=1";
else
cout << "the number < 0 !! try again";
getch();
}







3 - multiplication table for any number we choose:

#include <iostream.h>
#include <conio.h>
void main ()
{
int i,b;
cout << "Enter number: ";
cin >> b;
for (i=0; i<=10; i++)
cout << "\n" << b * i;
getch ();
}







4 - This program is to examine student grades if successful or not:


#include <iostream.h>
#include <conio.h>
void main ()
{
int a,b;
cout << "Enter your mark: ";
cin >> a;
cout << "Enter the lowest mark: ";
cin >> b;
if (a>b)
cout << "pass";
else
cout << "not pass";
getch ();
}





5 - function call does not return values ​​and do not pass the transaction:


#include <iostream.h>
#include <conio.h>
void starline( );
void main( )
{
starline( );
cout << " Safa2 Jaidi\n";
starline( );
cout << " from Qalqilia " << endl;
cout << " Palestine " << endl;
starline( );
getch ();
}
void starline( )
{
for ( int j = 0; j < 17 ; j++)
cout << '*' ;
cout << endl ;
}



0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Premium Wordpress Themes