You are on page 1of 9

UNIVERSITY OF TECHNOLOGY AND APPLIED

SCIENCES

HIGHER COLLEGE OF TECHNOLOGY


DEPARTMENT OF ENGINEERING
SECTION EEE
Assignment
Semester: 3 A. Y: 2020 / 2021
Date of Assignment Posting: 17th June 2021 Time: 12:00 PM
Last Date of Submission: 25th June 2021 Time: 11:30 PM
Student Name
Student ID
Specialization Engineering

Level Diploma First Engineering

Course Name / Course Code Computer Programming for Engineering EECP1290

Section No. 10B

Question No. Max. Obtained Question No. Max. Marks Obtained


Marks Marks Marks
PART- 1
Q1 6.0

PART- 2
Q2 6.0
Q3 3.0
Grand Total Marks
____ /15
Course Lecturer: Mr. /Ms.

Student’s Declaration: (to be filled by student)


1. I understand that the work must be my own.
2. I understand that any copy for any answer or a part of answer of any question will result
in a zero mark in all the assignment.
3. I understand that answering another version of the assignment from another sub-group
will result in a zero mark in all the assignment.

I have read and acknowledge the above instructions.

Student Name: __________________ ID: _________ Signature: _________


(Digital Signature)

Moderator’sApproval: PC’sApproval:
PART – 1 (6 marks)
Q1 Draw the flowchart then write the C program that calculates the following summation [6]
using for loop and prints the result:
sum= (-9) + (-7) + (-5) + ................. + n
Where n is a positive integer number that is input by the user.

Flowchart [3 marks]

#include <stdio.h>
int main() {
int a=-9;
int n;
printf("Enter n:");
scanf("%d", &n);
int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+a;
i+2;
}
printf("Answer=%d",sum);

Page 2 of 9
Page 3 of 9
Program [3 marks]
PART – 2 (9 marks)

Q2 Draw the flowchart then write the C program using else if. The program reads one integer [6]
number k. According to the value of k, the program will calculate the value of m and
prints the result according to the following table:
Value of k Required Calculation
1 – 40 m=√ k 3.2

41 - 80 m= 3k 3+2 k ²+ 3 k
1
(-20) - 0 m=
2 k 4 +3
Any other value Wrong selection

Flowchart [3.0 marks]

#include <math.h>
#include <stdio.h>
int main() {
int k;
int m=0;
printf("Enter k:");
scanf("%d", &k);
if(k>0&&k<41)
{
m=sqrt(pow(k,3.2));
printf("answer=%d",m);
}
else if(k>40&&k<81)
{
m=3*pow(k,3)+2*pow(k,2)+3*k;

Page 4 of 9
printf("answer=%d",m);
}
else if(k<1&&k>-20)
{
m=1/(2*pow(k,4)+3);
printf("answer=%d",m);
}
else
printf("wrong question");
}

Page 5 of 9
Program [3.0 marks]

Page 6 of 9
Q3 Write a C program using switch. The program reads one character opr. Then it reads 2 [3.0]
integers K and L. According to opr the program will do one of the operations and prints
the result according to the following table:
Value of opr Required operation
D or d Divide K by L and display the results.
E or e Find the remainder of K with L and display the result.
F Find the maximum of K and L and display the result.
Any other value Wrong Operation

Program [3 marks]

#include <stdio.h>

int main() {

char opr;

int L;

int K;

printf( "Enter opr:");

scanf("%c", &opr);

printf( "Enter L:");

scanf("%d", &L);

printf( "Enter a K:");

scanf("%d", &K);

switch (opr) {

case 'D':

case 'd':

Page 7 of 9
printf("Answer:%d",K/L);

break;

case 'E':

case 'e':

printf("remainder:%d",K%L);

break;

case 'F':

if(L>K)

printf("greater:%d",L);

else

printf("greater:%d",K);

break;

default:

printf("wroong question\n");

}}

Page 8 of 9
__________________ End of the Assignment __________________

Page 9 of 9

You might also like