C

 C – Code for Bank Application

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

// Structure declaration
struct acc_type
{
     char bank_name[20];
     char bank_branch[20];
     char acc_holder_name[30];
     int acc_number;
     char acc_holder_address[100];
     float available_balance;   
};
struct acc_type account[20];

/*
     printf("The above structure can be declared using
     typedef like below");

     typedef struct acc_type
     {
        char bank_name[20];
        char bank_branch[20];
        char acc_holder_name[30];
        int acc_number;
        char acc_holder_address[100];
        float available_balance;   
     }Acc_detail;

     Acc_detail account[20];
*/

int num_acc;

void Create_new_account();
void Cash_Deposit();
void Cash_withdrawl();
void Account_information();
void Log_out();
void display_options();

/* main program */
int main()
{
    char option;
    char f2f[50] = "http://fresh2refresh.com/";
    num_acc=0;
    while(1)
    {
       printf("\n***** Welcome to Bank Application *****\n");
       printf("\nThis demo program is brought you by %s",f2f);
       display_options();
       printf("Please enter any options (1/2/3/4/5/6) ");
       printf("to continue : ");

        option = getch();
        printf("%c \n", option);
        switch(option)
        {
          case '1': Create_new_account();
                    break;
          case '2': Cash_Deposit();
                    break;
          case '3': Cash_withdrawl();
                    break;
          case '4': Account_information();
                    break;
          case '5': return 0;
          case '6': system("cls");
                    break;
          default : system("cls");
                    printf("Please enter one of the options");
                    printf("(1/2/3/4/5/6) to continue \n ");
                    break;
        }
    }
    return 0;
}

/*Function to display available options in this application*/

void display_options()
{
    printf("\n1. Create new account \n");
    printf("2. Cash Deposit \n");
    printf("3. Cash withdrawl \n");
    printf("4. Account information \n");
    printf("5. Log out \n");
    printf("6. Clear the screen and display available ");
    printf("options \n\n");
}

/* Function to create new account */

void Create_new_account()
{
   char bank_name[20];
   char bank_branch[20];
   char acc_holder_name[30];
   int acc_number;
   char acc_holder_address[100];
   float available_balance = 0;
   fflush(stdin);   
   printf("\nEnter the bank name              : ");
   scanf("%s", &bank_name);
   printf("\nEnter the bank branch            : ");
   scanf("%s", &bank_branch);
   printf("\nEnter the account holder name    : ");
   scanf("%s", &acc_holder_name);
   printf("\nEnter the account number(1 to 10): ");
   scanf("%d", &acc_number);
   printf("\nEnter the account holder address : ");
   scanf("%s", &acc_holder_address);

   strcpy(account[acc_number-1].bank_name,bank_name);
   strcpy(account[acc_number-1].bank_branch,bank_branch);
   strcpy(account[acc_number-1].acc_holder_name,
   acc_holder_name);
   account[acc_number-1].acc_number=acc_number;
   strcpy(account[acc_number-1].acc_holder_address,
   acc_holder_address);
   account[acc_number-1].available_balance=available_balance;

   printf("\nAccount has been created successfully \n\n");
   printf("Bank name              : %s \n" ,
   account[acc_number-1].bank_name);
   printf("Bank branch            : %s \n" ,
   account[acc_number-1].bank_branch);
   printf("Account holder name    : %s \n" ,
   account[acc_number-1].acc_holder_name);
   printf("Account number         : %d \n" ,
   account[acc_number-1].acc_number);
   printf("Account holder address : %s \n" ,
   account[acc_number-1].acc_holder_address);
   printf("Available balance      : %f \n" ,
   account[acc_number-1].available_balance);

   //num_acc++;

}

// Displaying account informations

void Account_information()
{
     register int num_acc = 0;
     //if (!strcmp(customer,account[count].name))
     while(strlen(account[num_acc].bank_name)>0)
     {
         printf("\nBank name                : %s \n" ,
         account[num_acc].bank_name);
         printf("Bank branch              : %s \n" ,
         account[num_acc].bank_branch);
         printf("Account holder name      : %s \n" ,
         account[num_acc].acc_holder_name);
         printf("Account number           : %d \n" ,
         account[num_acc].acc_number);
         printf("Account holder address   : %s \n" ,
         account[num_acc].acc_holder_address);
         printf("Available balance        : %f \n\n" ,
         account[num_acc].available_balance);
         num_acc++;
     }
}

// Function to deposit amount in an account

void Cash_Deposit()
{
   auto int acc_no;
   float add_money;

   printf("Enter account number you want to deposit money:");
   scanf("%d",&acc_no);
   printf("\nThe current balance for account %d is %f \n",
   acc_no, account[acc_no-1].available_balance);
   printf("\nEnter money you want to deposit :  ");
   scanf("%f",&add_money);

   while (acc_no=account[acc_no-1].acc_number)
   {
         account[acc_no-1].available_balance=
         account[acc_no-1].available_balance+add_money;
         printf("\nThe New balance for account %d is %f \n",
         acc_no, account[acc_no-1].available_balance);
         break;
   }acc_no++;
}

// Function to withdraw amount from an account

void Cash_withdrawl()
{
   auto int acc_no;
   float withdraw_money;

   printf("Enter account number you want to withdraw money:");
   scanf("%d",&acc_no);
   printf("\nThe current balance for account %d is %f \n",
   acc_no, account[acc_no-1].available_balance);
   printf("\nEnter money you want to withdraw from account ");
   scanf("%f",&withdraw_money);

   while (acc_no=account[acc_no-1].acc_number)
   {
         account[acc_no-1].available_balance=
         account[acc_no-1].available_balance-withdraw_money;
         printf("\nThe New balance for account %d is %f \n",
         acc_no, account[acc_no-1].available_balance);
         break;
   }acc_no++;
}

C printf() function:


        printf() function is used to print the “character, string, float, integer, octal and hexadecimal values” onto the output screen.
        We use printf() function with %d format specifier to display the value of an integer variable.
        Similarly %c is used to display character, %f for float variable, %s for string variable, %lf for double and %x for hexadecimal variable.
        To generate a newline,we use “\n” in C printf() statement.

Note:

        C language is case sensitive. For example, printf() and scanf() are different from Printf() and Scanf(). All characters in printf() and scanf() functions must be in lower case.
 
#include <stdio.h>

int main()
{
   char  ch = 'A';
   char  str[20] = "loadyoursystem.blogspot.com";
   float flt = 10.234;
   int no = 150;

   double dbl = 20.123456;
   printf("Character is %c \n", ch);
   printf("String is %s \n" , str);
   printf("Float value is %f \n", flt);
   printf("Integer value is %d\n" , no);

   printf("Double value is %lf \n", dbl);
   printf("Octal value is %o \n", no);
   printf("Hexadecimal value is %x \n", no);

   return 0;

}

C Program to find area and circumference of circle


#include<stdio.h>

int main()
{
int rad;
float PI=3.14,area,ci;

printf("nEnter radius of circle: ");
scanf("%d",&rad);

area = PI * rad * rad;
printf("nArea of circle : %f ",area);

ci = 2 * PI * rad;
printf("nCircumference : %f ",ci);

return(0);
}

Output :

Enter radius of a circle : 1
Area of circle : 3.14
Circumference  : 6.28

Explanation of Program :

In this program we have to calculate the area and circumference of the circle. We have following 2 formulas for finding circumference and area of circle.

Area of Circle = PI * R * R

and

Circumference of Circle = 2 * PI * R

In the above program we have declared the floating point variable PI whose value is defaulted to 3.14.We are accepting the radius from user.

printf("nEnter radius of circle: ");
scanf("%d",&rad);

 

 ________________________________________________________
C programming #3

C Programming #2






Hello World In C.
#include <stdio.h>

int main()
{
   /* My first program */
   printf("Hello, World! \n");
  
   return 0;
}


An electric power distribution company charges its domestic consumers as follows:
 Consumption Units   Rate of Charge
 0-200     Rs.0.50 per unit
 201-400  Rs.100 plus Rs.0.65 per unit excess 200
 401-600  Rs.230 plus Rs.0.80 per unit excess of 400.
Write a C program that reads the customer number and power consumed and prints the amount to be paid by the customer. [Nov./Dec.-2005,Set-3, Unit-1, Q.No.-34]
Ans. : */
#include<stdio.h>
#include<conio.h>
void main()
{
int n, p;
float amount;
clrscr();
printf("Enter the customer number: ");
scanf("%d",&n);
printf("Enter the power consumed: ");
scanf("%d",&p);
if(p>=0 && p<=200)
 amount=p*0.50;
else if(p>200 && p<400)
 amount = 100+((p-200) * 0.65);
else if(p>400 && p<=600)
 amount = 230 + ((p-400) * 0.80);
printf("Amount to be paid by customer no. %d is Rs.:%5.2f.",n,amount);
getch();
}





Write a program to read the values of x, y and z and print the results of the following expressions in one line.


Ans. :
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
float a,b,c;
clrscr();
printf("Enter the values of x,y and z : ");
scanf("%d%d%d",&x,&y,&z);
a=(x+y+z)/(x-y-z);
b=(x+y+z)/3;
c=(x+y)*(x-y)*(y-z);
printf("a = %f\tb = %f\tc = %f",a,b,c);
getch();
}



Write a program to read a text file and convert the file contents in capital (Upper-case) and write the contents in a output file.

Ans. :
Program to copy the contents of one file into another*/
#include<stdio.h>
#include<process.h>

 void main()
  {
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("d:\\dtp\\test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("d:\\dtp\\test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
 {
 a=fgetc(fp1);
 a=toupper(a);

 fputc(a,fp2);
 }
 while(a!=EOF);
 fcloseall();
 getch();
}


Write a program to copy the contents of one file into another. [June-2005, Set-4, Unit-5, Q.No.-2]


Ans. :
Program to copy the contents of one file into another*/
#include<stdio.h>
#include<process.h>

 void main()
  {
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("d:\\dtp\\test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("d:\\dtp\\test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
 {
 a=fgetc(fp1);
 fputc(a,fp2);
 }
 while(a!=EOF);
 fcloseall();
 getch();
}

Post a Comment

Comment

Comment Box is loading comments...