If Block: It is used to execute a block of instructions if the condition is valid.

Program to give 15% discount to Customer if the bill amount is >= 5000
#include<stdio.h> int main(){ float bill=0, discount=0; printf(“Enter Bill amount : “); scanf(“%f”, &bill); if(bill>=5000) { discount = 0.15*bill; bill = bill-discount; } printf(“Final bill to pay : %f \n”, bill); printf(“Your discount is : %f \n”, discount); return 0; } |
Program to give 20% bonus to Employees having more than 5 years’ experience
#include<stdio.h> int main(){ int exp=0; float salary=0, bonus=0; printf(“Enter Employee salary : “); scanf(“%f”, &salary); printf(“Enter Expierience : “); scanf(“%d”, &exp); if(exp>5) { bonus = 0.20 * salary; salary = salary + bonus; } printf(“Your salary : %f \n”, salary); printf(“Bonus : %f \n”, bonus); return 0; } |