Showing posts with label while. Show all posts
Showing posts with label while. Show all posts

a demo program which represent the ATM transaction

ATM programing

ATM C programing language Program code

 ‎/*Note Pin code is 1234*/
#include<stdio.h>
#include<conio.h>

void main(void)
{ unsigned long amount=1000,deposit,withdr​aw;
int choice,pin=0,k=0;
char another='y';

while(pin!=1234)
{ clrscr();
gotoxy(30,25);
printf("Enter pin:");
scanf("%d",&pin);
}
clrscr();
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("\nYour Balance is Rs : %lu ",amount);
break;
case 2:
printf("\nEnter the amount to withdraw: ");
scanf("%lu",&withdraw);
if(withdraw%100!=0)
{
printf("\nPlease enter

amount in multiples of 100");
}else if(withdraw>(amount-500))
{

printf("\nInsufficient Funds");
}else
{

amount=amount-withdraw;

printf("\n\nPlease collect cash");

printf("\nYour balance is %lu",amount);
}
break;
case 3:
printf("\nEnter amount to deposit");
scanf("%lu",&deposit);
amount=amount+deposit;
printf("Your balance is %lu",amount);
break;
case 4:
printf("\nThank you for using ATM");
break;
default:
printf("\nInvalid Choice");
}
printf("\n\n\nDo you want another transaction?(y/n): ");
fflush(stdin);
scanf("%c",&another);
if(another=='n'||another==​'N')
k=1;
}while(!k);
printf("\n\nHave a nice day");
getch();

}

insertion sort using struct

2d example insertion sort

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

struct node
{
int number;
struct node *next;
};

struct node *head = NULL;

/* insert a node directly at the right place in the linked list */
void insert_node(int value);

int main(void)
{
struct node *current = NULL;
struct node *next = NULL;
int test[] = {8, 3, 2, 6, 1, 5, 4, 7, 9, 0};
int i = 0;

/* insert some numbers into the linked list */
for(i = 0; i < i =" 0;">next != NULL)
{
printf("%4d\t%4d\n", test[i++], head->number);
head = head->next;
}

/* free the list */
for(current = head; current != NULL; current = next)
next = current->next, free(current);

return 0;
}

void insert_node(int value)
{
struct node *temp = NULL;
struct node *one = NULL;
struct node *two = NULL;

if(head == NULL) {
head = (struct node *)malloc(sizeof(struct node *));
head->next = NULL;
}

one = head;
two = head->next;

temp = (struct node *)malloc(sizeof(struct node *));
temp->number = value;

while(two != NULL && temp->number <>number) {
one = one->next;
two = two->next;
}

one->next = temp;
temp->next = two;
}