Tuesday, November 25, 2014

Complex & ATM Transaction



C Program to add two Complex Numbers
 
#include 
#include
struct complex
{
   int realpart, imaginary;
};
 
main()
{
    struct complex a, b, c;
    clrscr();
    printf("Enter value of a and b complex number a + ib.\n");
    printf("Value of complex number a is = ");
    scanf("%d", &a.realpart);
    printf("Value of complex number b is = ");
    scanf("%d", &a.imaginary);
    printf("Enter value of c and d complex number c + id.\n");
    printf("Value of complex number c is = ");
    scanf("%d", &b.realpart);
    printf("Value of complex number d is = ");
    scanf("%d", &b.imaginary);
    c.realpart = a.realpart + b.realpart;
    c.imaginary = a.imaginary + b.imaginary;
    if (c.imaginary >= 0)
        printf("complex numbers sum is = %d + %di\n", c.realpart, c.imaginary);
    else
        printf("complex numbers sum = %d %di\n", c.realpart, c.imaginary);
    return 0;
}

Output
 
Enter value of a and b complex number a + ib.
Value of complex number a is = 10
Value of complex number b is = 12
Enter value of c and d complex number c + id.
Value of complex number c is = 15
Value of complex number d is = 22
Complex numbers sum is = 25 + 34i
 
C Program to Display Function without using the Main Function
#include 
#include
#define decode(s,t,u,m,p,e,d) 
#define begin decode(a,n,i,m,a,t,e)
 int begin()
{
 clrscr();    
printf(" Helloworld ");
getch();
}

Output

            Helloworld
C Program to Display the ATM Transaction
#include 
#include
unsigned long amount=1000, deposit, withdraw;
int choice, pin, k;
char transaction ='y';
clrscr();
void main()
{
   while (pin != 1520)
   {
               printf("Enter your secret pin number:");
               scanf("%d", &pin);
               if (pin != 1520)
               printf("Please enter valid password\n");
   }
   do
   {
               printf("********Welcome to ATM Service**************\n");
               printf("1. Check Balance\n");
               printf("2. Withdraw Cash\n");
               printf("3. Deposit Cash\n");
               printf("4. Quit\n");
               printf("******************?**************************?*\n\n");
               printf("Enter your choice: ");
               scanf("%d", &choice);
               switch (choice)
               {
               case 1:
                           printf("\n Your balance in Rs : %lu ", amount);
                           break;
               case 2:
                           printf("\n Enter the amount to withdraw: ");
                           scanf("%lu", &withdraw);
                           if (withdraw % 100 != 0)
                           {
                           printf("\n Please enter the amount in multiples of 100");
                           }
                           else if (withdraw >(amount - 500))
                           {
                                       printf("\n Insufficent balance");
                           }
                           else
                           {
                                       amount = amount - withdraw;
                                       printf("\n\n Please collect cash");
                                       printf("\n Your current balance is%lu", amount);
                           }
                           break;
               case 3:
                           printf("\n Enter the amount to deposit");
                           scanf("%lu", &deposit);
                        amount = amount + deposit;
                           printf("Your balance is %lu", amount);
                           break;
               case 4:
                           printf("\n Thank u using atm");
                           break;
               default:
                           printf("\n Invalid choice");
               }
               printf("\n\n\n Do u wish to have another transcation?(y/n): \n");
               fflush(stdin);
               scanf("%c", &transaction);
               if (transaction == 'n'|| transaction == 'N')
                    k = 1;
   } while (!k);
   printf("\n\n Thanks for using out atm service");
   getch();
}
 
Output

Enter your secret pin number:1520
********Welcome to ATM Service**************
1. Check Balance
2. Withdraw Cash
3. Deposit Cash
4. Quit
******************?**************************?*
Enter your choice: 1
Your balance in Rs : 1000
 Do u wish to have another transcation?(y/n):
********Welcome to ATM Service**************
1. Check Balance
2. Withdraw Cash
3. Deposit Cash
4. Quit
******************?**************************?*
Enter your choice: 2
Enter the amount to withdraw: 200
Please collect cash
Your current balance IS800
Do u wish to have another transcation?(y/n):
********Welcome to ATM Service**************
1. Check Balance
2. Withdraw Cash
3. Deposit Cash
4. Quit
******************?**************************?*

No comments:

Post a Comment