0% found this document useful (0 votes)
0 views

C PROGRAM ASS-1

The document outlines three programming assignments in C for a course (CS3251). The first assignment involves calculating electricity bills based on meter readings, the second focuses on finding neighboring train berth numbers, and the third requires determining the minimum number of currency notes and coins for a given amount. Each assignment includes input and output formats along with sample inputs and expected outputs.

Uploaded by

22ee137
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

C PROGRAM ASS-1

The document outlines three programming assignments in C for a course (CS3251). The first assignment involves calculating electricity bills based on meter readings, the second focuses on finding neighboring train berth numbers, and the third requires determining the minimum number of currency notes and coins for a given amount. Each assignment includes input and output formats along with sample inputs and expected outputs.

Uploaded by

22ee137
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

ASSIGNMENT-1

PROGRAMMING IN C -CS3251

NAME:PAVITHRA J
REG NO:715524104107
CLASS :CSE-B
____________________________________________________
Q.NO:1

Babu wants to design software to calculate the Electricity bill. He needs to calculate the final amount
based on meter reading. Help babu to calculate the electricity bill based on the initial and final meter
reading.

Input Format

Initial reading in the meter Final reading in the meter

Constraints

Initial reading in the meter<=Final reading in the meter

Output Format
Total amount

Sample Input 0

400
1200

Sample Output 0

Rs. 3760.00

Sample Input 1

1200
1100

Sample Output 1

Invalid Input
SOLUTION:

#include <stdio.h>

int main()

int initial_reading,final_reading,units,fixed_charge;

float cost,total;

scanf("%d",&initial_reading);

scanf("\n%d",&final_reading);

units=final_reading-initial_reading;

if(initial_reading<=final_reading)

if(units<=100)

{
fixed_charge=0;

cost=0;

else if(units<=200)

fixed_charge=20;

cost=(units-100)*2.0;

else if(units<=500)

fixed_charge=30;

cost=(100*2.0)+((units-200)*3.0);

else

fixed_charge=50;

cost=(100*3.5)+(300*4.6)+((units-500)*6.6);

total=fixed_charge+cost;

printf("Rs. %.2f",total);

else

{
printf("Invalid Input");

return 0;

LEADER BOARD:

Q.NO:2

Tim and Bob are off to a famous Education Fair "Knowledge Forum 2022" at Chennai.
This time they have to travel without their guardians. Tim got very interested in the
arrangement of seats inside the train coach.

The entire coach could be viewed as an arrangement of consecutive blocks of size 8.


and the pattern is repeated for every set of 8 berths.

Tim and Bob are playing this game of finding the co-partner in train of each berth. Write
a program to do the same.

Input Format

The input consists of an integer N, which corresponds to the berth number whose
neighbor is to be found out.

Constraints

-
Output Format

The output is to display the berth of the neighbor of the corresponding seat. Refer
sample input and output for formatting specifications.

Sample Input 0

Sample Output 0

4LB

Sample Input 1

Sample Output 1

2MB
SOLUTION;

#include <stdio.h>

void my_co_pa(int a) {

int partner[] = {4, 5, 6, 1, 2, 3, 8, 7};

char *seat[] = {"LB", "MB", "UB", "LB", "MB", "UB", "SL", "SU"};

int pos = (a - 1) % 8;

int co_seat = ((a - 1) / 8) * 8 + partner[pos];

printf("%d%s\n", co_seat, seat[partner[pos] - 1]);


}

int main() {

int a;

scanf("%d", &a);

my_co_pa(a);

return 0;

LEADER BOARD:
Q.NO:3

Joseph recently joined a nationalized bank. His daily task is to give the amount to
customers. He wants to find the minimum number of notes/coins required for the given
amount. Write a program to input the amount from the user and print the minimum
number of notes and coins (Rs.2000, Rs. 500, Rs.200, Rs.100, Rs.50, Rs.20, Rs.10,
Rs5, Rs.2, Rs.1) required for the amount.

Input Format

Amount in firstline

Constraints

Notes -Rs.2000, Rs. 500, Rs.200, Rs.100, Rs.50, Rs.20, Rs.10


Coins -Rs5, Rs.2, Rs.1

Output Format

Denomination as shown in sample output.

Sample Input 0

2888

Sample Output 0

Denomination

2000 = 1

500 = 1

200 = 1

100 = 1

50 = 1

20 = 1

10 = 1

5=1

2=1

1=1

Sample Input 1
159

Sample Output 1

Denomination

2000 = 0

500 = 0

200 = 0

100 = 1

50 = 1

20 = 0

10 = 0

5=1

2=2

1=0
SOLUTION:

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

int main() {

int amount;

scanf("%d",&amount);

int denominations[]={2000,500,200,100,50,20,10,5,2,1};

int count[10]={0};

printf("Denomination\n");

for (int i=0;i<10;i++)


{

count[i]= amount / denominations[i];

amount%=denominations[i];

printf("%d = %d\n",denominations[i],count[i]);

return 0;

LEADER BOARD:

You might also like