0% found this document useful (0 votes)
15 views3 pages

C programming Midterm Exam SPRING 2024 Model Answer

The document is a mid-term exam for the Programming Essentials in C course at October Technological University, consisting of multiple-choice questions, a simple program to calculate the area of a circle, a decision-making program to check if a number is positive or negative, and a looping program to calculate the factorial of a number. It includes code snippets and explanations for each question. The exam is supervised by Prof. Dr. Tarek Abdul Hamid.

Uploaded by

malakmahamad376
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)
15 views3 pages

C programming Midterm Exam SPRING 2024 Model Answer

The document is a mid-term exam for the Programming Essentials in C course at October Technological University, consisting of multiple-choice questions, a simple program to calculate the area of a circle, a decision-making program to check if a number is positive or negative, and a looping program to calculate the factorial of a number. It includes code snippets and explanations for each question. The exam is supervised by Prof. Dr. Tarek Abdul Hamid.

Uploaded by

malakmahamad376
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/ 3

Faculty of Industry and Energy Technology Mid Term Exam October Technological University

Subject : Programming Essentials in C Date : 30 / 03 / 2024


Time allowed: 1 hour 1st Year Program :Information Technology
Examiners Committee: Prof. Dr. Tarek Abdul Hamid
Name:……………………………………………. ID:…………………………………….
Question I MCQ: (5 Marks – ONE Mark Each)
1. What will be the output of the following C code?
A. Hello World!
B. Hello World! 34
C. Hello World! Followed by a junk value
D. None of This

2. What will be the output of the following C code?


A. 3
B. 3.75
C. 24
D. None of This

3. What will be the output of the following C code?


A. 5
B. 6
C. Error
D. None of This

Explanation:
We cannot modify a constant integer value.

4. What will be the output of the following C code?


A. Hi
B. Bye
C. HiBye
D. Compilation Error

Explanation:
F(0) means false so the output will be the else probability “bye”.

5. What is the output of the following C code?


A. 1
B. 2
C. 1 2
D. None of This
Question II: Simple Program: (5 Marks)
Write a C Program to find Area of a Circle.
A= πr2
Solution:

#include <stdio.h>
const float PI = 3.14159;
int main()
{
float radius, area;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);

area = PI * radius * radius;

printf("The area of the circle is: %f", area);

return 0;
}

Question III: Decision Making: (10 Marks)


Write a c program to check the Number is Positive or Negative.

Solution:

#include <stdio.h>

int main() {

double num;
printf("Enter a number: ");
scanf("%lf", &num);
if (num <= 0.0) {
if (num == 0.0)
printf("You entered 0.");
else
printf("You entered a negative number.");
}
else
printf("You entered a positive number.");

return 0;
}

Page 2 of 3
Question IV: Looping: (10 Marks)

Write a C++ program to input a Positive Integer Number and calculate the Factorial of the Number.

Solution:

#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);

// shows error if the user enters a negative integer


if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %llu", n, fact);
}

return 0;
}

Good Luck - Dr. Tarak Abdul Hamid

Page 3 of 3

You might also like