You are on page 1of 11

LAB ASSIGNMENT- 4

NAME : Jakia Rahman

DEPARTMENT : Computer Science and Engineering

SEMESTER : 1st (spring-2020)

MATRIC ID : C-201234

COURSE CODE : CSE-1122


Problem no. 01 : Write a C program to read the the number of units consumed
and print out the net bill .

Solution :

#include<stdio.h>

int main()

int unit;

float amount,net_bill,minimum_charge;

minimum_charge=90;

printf("Enter the unit : ");

scanf("%d",&unit);

//here, the minimum consumable unit is 90/4.5=20.

if(unit>=20 && unit<=250)

amount=unit*4.5;

else if(unit>=250)

amount=250*4.5+((unit-250)*72);
}

else

printf("\n\nThe minimum consumption of unit is 20 so \nplease enter any


unit greater than 20 . ");

net_bill=amount+minimum_charge;

printf("\n\nThe net bill is : %.2f",net_bill);

return 0;

}
Problem no. 02 : Write a C program to input basic salary of an employee and
calculate the gross salary .

Solution :

#include<stdio.h>

int main()

float basic_salary,gross_salary,da,hra;

printf("Enter basic salary of the employee : ");

scanf("%f",&basic_salary);

if(basic_salary<=10000)

da=basic_salary*0.8;

hra=basic_salary*0.2;

else if(basic_salary<=20000)

da=basic_salary*0.9;

hra=basic_salary*0.25;

else

{
da=basic_salary*0.95;

hra=basic_salary*0.3;

gross_salary=basic_salary+da+hra;

printf("\nGross salary of the employee is : %.2f ",gross_salary);

return 0;

}
Problem no. 03 : Write a C program to check whether the number is odd or
even using switch .

Solution :

#include<stdio.h>

int main(){

int integer;

int remainder;

printf("Enter an integer to find odd and even : ");

scanf("%d",&integer);

remainder=integer%2;

switch(remainder)

case 0:

printf("\nThis integer is even . ");

break;

default:

printf("\nThis integer is odd . ");

return 0;

}
Problem no. 04 : Write a C program to design basic operations of a calculator
using switch .

Solution :

#include <stdio.h>

int main() {

char operator;

float n1, n2;

printf("Enter an operator (+, -, *, /): ");

scanf("%c", &operator);

printf("Enter two operands: ");

scanf("%f %f",&n1, &n2);

switch(operator)

case '+':

printf("%.1f + %.1f = %.1f",n1, n2, n1+n2);

break

case '-':

printf("%.1f - %.1f = %.1f",n1, n2, n1-n2);

break;

case '*':
printf("%.1f * %.1f = %.1f",n1, n2, n1*n2);

break;

case '/':

printf("%.1f / %.1f = %.1f",n1, n2, n1/n2);

break;

default:

printf("Please enter a valid operator . ");

return 0;

}
Problem no. 05 : Write a C program to print gender (male/female) according
to the given input m/f using switch .

Solution :

#include<stdio.h>

int main()

char gender;

printf("Enter gender code (m/M OR F/f) : ");

scanf("%c",&gender);

switch(gender)

case'm':

case'M':

printf("\nThis is male");

break;

case'f':

case'F':

printf("\nThis is female");

break;
default:

printf("Enter valid character");

return 0;

Problem no. 06 : Write a switch statement that will examine the value of an
integer variable called department and print messages depending on the value
assigned to department .

Solution :

#include<stdio.h>

int main()

int department;

printf("Enter the department number : ");

scanf("%d",&department);

switch(department)

case 1:
printf("\nThis is CSE department.");

break;

case 2:

printf("\nThis is EEE department.");

break;

case 3:

printf("\nThis is ETE department.");

break;

default:

printf("\nOut of range of engineering faculty.");

return 0;

You might also like