 # C Programming Code Examples

## C > If Else and Switch Case Code Examples

### C program to calculate electricity bill

``` C program to calculate electricity bill Write a C program to input electricity unit charge and calculate the total electricity bill according to the given condition: For first 50 units Rs. 0.50/unit For next 100 units Rs. 0.75/unit For next 100 units Rs. 1.20/unit For unit above 250 Rs. 1.50/unit An additional surcharge of 20% is added to the bill. How to calculate electricity bill using if else in C programming. Program to find electricity bill using if else in C. Logic to find net electricity bill in C program. Input unit consumed by customer in some variable say unit. If unit consumed less or equal to 50 units. Then amt = unit * 0.50. If unit consumed more than 50 units but less than 100 units. Then add the first 50 units amount i.e. 25 to final amount and compute the rest 50 units amount. Which is given by amt = 25 + (unit-50) * 0.75. I have used units-50, since I already calculated first 50 units which is 25. Similarly check rest of the conditions and calculate total amount. After calculating total amount. Calculate the surcharge amount i.e. sur_charge = total_amt * 0.20. Add surcharge amount to net amount. Which is given by net_amt = total_amt + sur_charge. #include <stdio.h> int main() { int unit; float amt, total_amt, sur_charge; /* Input unit consumed from user */ printf("Enter total units consumed: "); scanf("%d", &unit); /* Calculate electricity bill according to given conditions */ if(unit <= 50) { amt = unit * 0.50; } else if(unit <= 150) { amt = 25 + ((unit-50) * 0.75); } else if(unit <= 250) { amt = 100 + ((unit-150) * 1.20); } else { amt = 220 + ((unit-250) * 1.50); } /* * Calculate total electricity bill * after adding surcharge */ sur_charge = amt * 0.20; total_amt = amt + sur_charge; printf("Electricity Bill = Rs. %.2f", total_amt); return 0; } ```

Program code to search for a Palindrome - C Programming language code to search for a palindrome. Please enter a word, phrase or sentence below(type END to exit the program). String is a palindrome or it is not...

C Code Rotate left rotate an Array n times - C program code to left rotate an array by n position. Logic to rotate an array to left by n position in C program. Read elements in an array say arr. Read number of times to rotate

Access Elements of an Array Using Pointer - Program Declares the array of five element & the elements of that array are accessed using pointer. The five elements are entered by the user and stored in the integer array data. And

Increment Operator Decrement Operator - Basic "arithmetic operators" are +, -, *, /, %. "Increment operator" is ++ and "decrement operator" is --. These operators can be used as before the variable (prefix) and after the

Program Displays the Transpose of Matrix - To transpose any matrix in C++ Programming language, you have to first ask to the user to enter the matrix and "replace row" by column and column by row to "transpose" that matrix

Reverse Counting program in C Language - C Program reverse counting is sequence of whole numbers in descending order without zero. Developing a program of counting in C programming language is easy and we shall

Returns Nonzero if ch is White-Space Char - C program Returns nonzero if ch is a white-space character, including space, horizontal tab, vertical tab, formfeed, carriage return, or newline character; otherwise zero is return.

C Put Even & Odd Elements of an Array in - C Program puts even & odd elements of an array in 2 separate arrays. The program first finds the odd and even elements of the array. Then the odd elements of an array is stored