Posts

Showing posts with the label while

Loops in C

Image
How to use Loops in C In any programming language including C, loops are used to execute a set of statements repeatedly until a particular condition is satisfied. How it Works The below diagram depicts a loop execution, As per the above diagram, if the Test Condition is true, then the loop is executed, and if it is false then the execution breaks out of the loop. After the loop is successfully executed the execution again starts from the Loop entry and again checks for the Test condition, and this keeps on repeating. The sequence of statements to be executed is kept inside the curly braces { } known as the Loop body . After every execution of the loop body, condition is verified, and if it is found to be true the loop body is executed again. When the condition check returns false , the loop body is not executed, and execution breaks out of the loop. Types of Loop There are 3 types of Loop in C language, namely: while loop for loop do while loop while

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("\

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 *)ma