Lab Sessional - SP2021

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

COMSATS University Islamabad

Attock Campus
Department of Electrical and Computer Engineering

Program: BCE-2Spring 2021


LabSessional I
Course: Programming Fundamentals
Time Allowed: 1h 10mins Marks: 30
Name: ______________________________________ Reg. No: _______________________________
Note: Each question carries 15 marks
Instructor’s E-mail id: laraib@cuiatk.edu.pk
Instructions:
1. You have to submit your answer document & code file via both MS Teams & email.
2. Save document file with your Name and Registration number.
3. No late answers would be accepted.

Question 1: [CLO-1,4]

A company gives a certain amount of allowance to its employee in the following cases:
− 30% of basic salary if the employee is married and has children.
− 20% of basic salary if the employee is unmarried, male & has experience of 5 years.
− 20% of basic salary if the employee is unmarried, female & has experience of 4 years.
In all other cases the employee is not given an allowance. If the basic salary, marital status, gender
and experience of the employee are the inputs, write a program to determine whether the employee
will get an allowance or not and compute his total salary.

Question 2: [CLO-2,4]

A 5-digit positive integer is entered through the keyboard, write a function to check how much
number of its digits is even and odd and then display those digits respectively. Some sample
interaction with the program might look like this:
Enter a five digit number: 92347
The number of even digits in 92347 is 2 and even digits are 2& 4.
The number of odd digits in 92347 is 3 and odd digits are 9,3& 7.
Answer:
Coding:
#include <stdio.h>
int main()
{

char marital, gender, child,basic_s,total_s;


int exper;
printf("Enter the Basic Salary: ");
scanf("%d", &basic_s);
printf("Enter the experience: ");
scanf("\n%d", &exper);
printf("Enter the Marital Status, 'm' for Married & 'u' for Unmarried: ");
scanf("\n%c", &marital);
printf("Enter the Gender, 'm' for Male & 'f' for Female: ");
scanf("\n%c", &gender);
printf("Do you have children?, 'y' for Yes & 'n' for No: ");
scanf("\n%c", &child);
if (marital=='m' && child=='y')
{
total_s = basic_s*0.3;
printf("Allowance of 30 percent of basic salary will be given.");
printf("Total salary is %d", total_s);
}
else if (marital =='u' && gender =='m' && exper =='5')
{ }
else if (marital =='u' && gender =='m' && exper =='5')
{
total_s = basic_s*0.2;
printf("Allowance of 20 percent of basic salary will be given.");
printf("Total salary is %d", total_s);
}
else if (marital =='u' && gender =='f' && exper =='4')
{
total_s = basic_s*0.2;
printf("Allowance of 20 percent of basic salary will be given.");
printf("Total salary is %d", total_s);
}
else
printf("The employee will not get allowance.");
}
Output:

Answer:
Coding:
int main ()
{
int num,num1,num2,num3,num4,num5,numm;
printf("enter the five digit number");
scanf("%d",&num);
numm=num;
num5=num%10;
num=num/10;
num4=num%10;
num=num/10;
num3=num%10;
num=num/10;
num2=num%10;
num=num/10;
num1=num%10;
if (num1%2)
{
printf("Enter numbers are even:")
}
else
{
printf("Enter numbers are odd:")
}}
Output:

You might also like