Sep 24, 2011

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

1-This program will analyze the number of primary factors:


#include <iostream.h>
#include <conio.h>
void main ()
{
int j, n;
char ch;
do
{
cout << "Enter a numbers: ";
cin >> n;
for (j = 2 ; j <= n/2; j++)
if ( n % j == 0 )
cout << n << " divisible by: " << j << endl ;
cout << "again (y/n)?";
cin >> ch;
}
while (ch != n);
getch ();
}








2-Largest number among three numbers (the shortcut method):


#include <iostream.h>
#include <conio.h>
void main ()
{
float a , b , c , max ;
char ch;
do
{
cout << "\nEnter three numbers: \n" ;
cin >> a >> b >> c;
max = (a > b ) ? ((a > c) ? a:c ): ((b > c) ? b:c );
cout << max << " is the grater.\n" ;
cout << "\nagain (y/n)?";
cin >> ch;
}
while (ch != 'n');
getch ();
}








3-The way the program calculates the shortcut monthly net salary after tax it according toconditions:
2% will be deducted from the salary that is less than or equal to 1000
3% will be deducted from the salary that between the 1000 and the 2000:

#include <iostream.h>
#include <conio.h>
void main ()
{
float S, N;
L: cout << "\nEnter your salary: " ;
cin >> S;
N =(S <= 1000) ? S-S*.02:((S>=2000) ? S-S*.04 : S-S*.03);
cout << "Net salary after tax is: " << N << endl;
goto L;
getch ();
}








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