Home » Ask & Discuss » Other Courses » Computer Applications « Back to Discussion



Computer Applications

vivek's Avatar
Scorching goIITian

Joined: 28 Sep 2008
Post: 249
2 Nov 2008 00:07:26 IST
0 People liked this
1
703 View Post
WAP TO CALCULATE SIMPLE INTEREST,COMPUND INTEREST,FACTORIAL AND PRIME NOS USING FUNCTIONS,
None

WAP TO CALCULATE SIMPLE INTEREST,COMPUND INTEREST,FACTORIAL AND PRIME NOS USING FUNCTIONS,


Share this article on:

Comments (1)

Mirka's Avatar

Blazing goIITian

Joined: 13 Aug 2008
Posts: 1313
2 Nov 2008 19:35:17 IST
2 people liked this



 HERE'S THE PROGRAM, IT WORKS PERFECTLY ON MY COMPILER!!


BUT JUST ADJUST THE SPACINGS, THE PROBLEM'S DUE TO THIS EDITOR.....


 


#include<iostream.h>

#include<math.h>


void simple_int ( );

void comp_int ( );

void factorial ( );    
/* Function prototypes */

void prime ( );


void main ( )

{

  int ch;

  char yn;


  do

 {

   cout<<"\n\n MENU \n"; 
/* Displaying Menu */

   cout<<"\n 1. Simple Interest ";

   cout<<"\n 2. Compound Interest ";

   cout<<"\n 3. Factorial ";

   cout<<"\n 4. Prime no. ";

   cout<<"\n\n\t Enter ur choice ... ";

   cin>>ch;


   switch (ch)

  {

   case 1: simple_int ( ); break;

   case 2: comp_int ( ); break;

   case 3: factorial ( ); break;

   case 4: prime ( ); break;

   default: cout<<"\n Invalid choice!! "; break;

  }


   cout<<"\n\n\n Continue (y/n)?? ...   ";

   cin>>yn;

 }

  while ( (yn=='y')||(yn=='Y') );


     /* end of do-while loop and main */

}


void simple_int ( )

 {

 float p, r, t, si;

 cout<<"\n\n Enter Principal in Rs.  ";

 cin>>p;

 cout<<"\n Enter time in years  ";

 cin>>t;

 cout<<"\n Enter rate per year  ";

 cin>>r;


 si = p*r*t/100;  /* Calculating Simple Interest */


 cout<<"\n\n The Simple Interest is Rs. "<<si;


 }


void comp_int ( )

 {

 float p, r, ci;

 int t;

 cout<<"\n\n Enter Principal in Rs.  ";

 cin>>p;

 cout<<"\n Enter time in years  ";

 cin>>t;

 cout<<"\n Enter rate per year  ";

 cin>>r;


 ci = p* pow(( 1 + r/100 ), t);


    /* Calculating Compound Interest */


   cout<<"\n\n The Compound Interest is Rs. "<<ci;


 }


void factorial ( )

 {

 int f = 1;

 int i, n;

 cout<<"\n\n Enter the no.whose factorial is 2 b found \n";

 cin>>n;




 for (i=1; i<=n; i++)

   f = f*i;  
/* Finding the factorial */


 cout<<"\n\n "<<n<<" !  =   "<<f;


 }


void prime ( )

 {

 int c, i, n;

 c = 0;


 cout<<"\n\n Enter the number  ";

 cin>>n;


 for (i=1; i<=n; i++)

  {

  if ( n%i == 0 )

    c++;    
/* Checking 4 any divisors */

  }


 if ( c==2 )

   cout<<"\n "<<n<<" is a prime number. ";

 else

   cout<<"\n "<<n<<" is not a prime number. ";


 }


 


RATE !!       

 




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads