You are on page 1of 6

LAB ASSIGNMENT- 5

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 print out the encoded version of the
given words.

Solution :
#include<stdio.h>

int main()

char x[6];

char en[6];

printf("Enter the word : ");

scanf("%s",x);

en[0] = x[0] - 30;

en[1] = x[1] - 30;

en[2] = x[2] - 30;

en[3] = x[3] - 30;

en[4] = x[4] - 30;

en[5] = '\0';

printf("\nThe original word is '%s' \n and the encoded word is '%s' .\n ",x,en);

return 0;

}
Problem no. 02 : Write a C program to reverse a word’s uppercase into
lowercase and vice-versa.

Solution :
#include <stdio.h>

int main() {

char s[100];

int i;

printf("\nEnter the word : ");

scanf("%s",s);

for (i = 0; s[i]!='\0'; i++)

if(s[i] >= 'a' && s[i] <= 'z')

s[i] = s[i] - 32;

else if(s[i] >= 'A' && s[i] <= 'Z')

s[i] = s[i] + 32;

}
printf("\nThe converted word is = %s",s);

return 0;

Problem no. 05 : Write a C program to read the number of units and


print out the net bill .

Solution :
#include<stdio.h>

int main()

int unit,minimum_charge;

float amt, total_amt,net_amt, sur_charge;

sur_charge = 0.15;

minimum_charge = 120;

printf("Enter total units consumed: ");

scanf("%d", &unit);
if(unit <= 150)

amt = unit * 4.5;

else if(unit>=151 && unit<=450)

amt = 150*4.5+ ((unit-150) * 5.5);

else if(unit >= 400)

amt = (100*4.5) + (300* 5.5)+((unit-450)*7);

else

printf("Please enter a valid amount of unit .");

net_amt = amt + minimum_charge;

if(net_amt>10000)

{
total_amt = net_amt + (net_amt * sur_charge);

else

total_amt = net_amt;

printf("Electricity Bill = Rs. %.2f", total_amt);

return 0;

You might also like