Ete105 fall2014 lab_2 (East West University)

2
EAST WEST UNIVERSITY Department of Electronics & Communications Engineering Objectives: The main objective of this lab experiment to practice a number of programming problems, using the various types of operators in C. Exercise 1: Write a C program to calculate result of the following equation ) / 1 ( * ) ( ) /( 2 5 . 0 / 2 ) ( 8 . 8 m b a r q a c b a Z where, a=10, b=50, c=8, m=0.5, q=2.5, r=0.25. A sample output is given below: a=10 b=50 c=8 m=0.50 q=2.50 r=0.25 z=1.16 Exercise 2: Ramesh’s basic salary is input through the keyboard. His dearness allowance (DA) is 40% of basic salary, and house rent allowance (HRA) is 20% of basic salary. Write a program to calculate his gross salary. [Hint: Gross Salary=Basic Salary +DA+HRA] Lab Assignment: If the marks obtained by a student in four different subjects (e.g Physics, Math, English, Chemistry) are input through keyboard, find out the total marks and average marks obtained by the student. Note that the maximum marks that can be obtained by a student in each subject is 100. Fall 2014 Semester ETE 105 LAB Experiment 2: Simple Programs with C Operators Name: ID:

description

East West University ETE lecture for all.

Transcript of Ete105 fall2014 lab_2 (East West University)

Page 1: Ete105 fall2014 lab_2 (East West University)

EAST WEST UNIVERSITY

Department of Electronics & Communications Engineering

Objectives:

The main objective of this lab experiment to practice a number of programming problems, using

the various types of operators in C.

Exercise 1: Write a C program to calculate result of the following equation

)/1(*)(

)/(25.0/2)(8.8

mba

rqacbaZ

where, a=10, b=50, c=8, m=0.5, q=2.5, r=0.25.

A sample output is given below:

a=10

b=50

c=8

m=0.50

q=2.50

r=0.25

z=1.16

Exercise 2: Ramesh’s basic salary is input through the keyboard. His dearness allowance (DA)

is 40% of basic salary, and house rent allowance (HRA) is 20% of basic salary. Write a program

to calculate his gross salary.

[Hint: Gross Salary=Basic Salary +DA+HRA]

Lab Assignment:

If the marks obtained by a student in four different subjects (e.g Physics, Math, English,

Chemistry) are input through keyboard, find out the total marks and average marks

obtained by the student. Note that the maximum marks that can be obtained by a student

in each subject is 100.

Fall 2014 Semester

ETE 105 LAB

Experiment 2: Simple Programs with C Operators

Name: ID:

Page 2: Ete105 fall2014 lab_2 (East West University)

EAST WEST UNIVERSITY

Department of Electronics & Communications Engineering

Solutions

Exercise 1:

#include<stdio.h>

int main()

{

int a=10, b=50, c=8;

float q=2.5, r=0.25, m=0.5;

double x, y, z;

x=(8.8*(a+b)*2/c)-0.5+2*a/(q+r);

y=(a+b)*(1/m);

z=x/y;

printf("a=%d\n", a);

printf("b=%d\n", b);

printf("c=%d\n", c);

printf("m=%d\n", m);

printf("q=%5.2f\n", q);

printf("r=%5.2f\n", r);

printf("z=%5.2f\n", z);

return 0;

}

Exercise 2:

#include<stdio.h>

int main()

{

float BS, DA, HRA, GS;

printf("Enter the amount of Ramesh's basic salary:\n");

scanf("%f", &BS);

DA=0.4*BS;

HRA=0.2*BS;

GS=BS+DA+HRA;

printf("Ramesh's basic salary is: %7.2f\n", BS);

printf("Ramesh's gross salary is: %7.2f\n", GS);

return 0;

}