You are on page 1of 4

UNIQUE ID

B. Tech. DEGREE
ANSWER KEY - CONTINUOUS ASSESSMENT 2
OCT – 2020: I YEAR – QUARTER 1

CSE 110: Problem Solving – C Programming


(Common to AI & ML, CyS and IoT, AI & DA, CS & MED)

Time: 1 hour – 15 minutes Maximum Mark: 15 Date: 12/10/2020

Instruction to candidates:
1. Candidates should write the correct question number for the answered questions
2. Students should use A4 sheet for answering the questions
3. Unique ID should be mentioned at the top right corner of the answer sheet.

COURSE OUTCOMES
CO2: Understand and apply various concepts of C programming.
CO3: Ability to work with arrays and user defined data types

Answer ALL Questions


[3*5 = 15 Marks]

1. Consider the weekly salary of a salesperson who is selling some domestic products. If z [5] CO2 [K3]
is the number of products sold in a week, her weekly salary is given by

Implement the logic for decision on salary using conditional operator in C language.
Program

#include<stdio.h>
#include<stdlib.h>

int main()
{
int z;
float salary;
printf("\n Enter the number of products sold in a week:");
scanf("%d",&z);
salary = (z != 43) ? ((z < 43) ? (5*z+200) : (5.8*z+180)) : 800;
PAGE 1 OF 4
printf("The salary of sales person is:%f",salary);
}

Input and Output:


Enter the number of products sold in a week:30
The salary of sales person is:350.000000

Enter the number of products sold in a week:43


The salary of sales person is:800.000000

Enter the number of products sold in a week:50


The salary of sales person is:470.000000
2. The rack of a bookshelf contains ordered indices on six book titles. "C for all" is one [5] CO3 [K3]

of the book titles. Implement the logic using C language to locate the title.
Program:
#include<stdio.h>
#include<string.h>
int main()
{
char rack[10][20]={"Let Us C","Test your C skills","C Programming","C for
all","ANSI C ","Programming in C"};
char find[]="C for all";
int n=6,i=0;
for(i=0;i<n;i++){
if(strcmpi(rack[i],find)==0)
{
printf("The title %s is found at position %d",find,i+1);
}
}
return 0;
}
Output: The title C for all is found at position 4.
3. An automobile company has serial number for engine parts starting from AA0 to FF9. [5] CO3 [K3]

The other characteristics of parts to be specified in a structure are: Year of manufacture,


material and quantity manufactured. Implement the logic using C language to perform
the following operations.
a) Specify a structure to store information corresponding to a part.
b) Retrieve information on parts with serial numbers between BB1 and CC6.
Program:

#include<stdio.h>
#include<stdlib.h>
struct parts
{

PAGE 2 OF 4
char sl[4],material[10];
int yr,qty;
};

int main()
{
int i;
struct parts p[3];
for(i=0;i<3;i++)
{
printf("Enter sl no\n");
fflush(stdin);
gets(p[i].sl);
printf("Enter year of manufacture , material and quantity\n");
scanf("%d%s%d",&p[i].yr,&p[i].material,&p[i].qty);
}
for(i=0;i<3;i++)
{
if(p[i].sl[0]=='A')
continue;
if((p[i].sl[0]=='B'&&p[i].sl[2]=='1')||(p[i].sl[0]=='C'&&p[i].sl[0]>'6'))
continue;
printf("%s %d %s %d\n",p[i].sl,p[i].yr,p[i].material,p[i].qty);
}
return 0;
}

Input:
Enter sl no
BB2
Enter year of manufacture, material and quantity
2020
Iron
2

Enter sl no
BB4
Enter year of manufacture, material and quantity
2020
Wood
3

Enter sl no
CC8
Enter year of manufacture, material and quantity
2020
Rubber
2

PAGE 3 OF 4
Output:
Serial number Year of Manufacture Material Quantity
BB2 2020 Iron 2
BB4 2020 Wood 3

PAGE 4 OF 4

You might also like