0% found this document useful (0 votes)
12 views4 pages

C Programming Quiz and Coding Tasks

The document consists of multiple choice questions, fill-in-the-blank statements, and coding problems related to the C programming language. It covers topics such as syntax, functions, variable types, and basic programming constructs. The coding section includes examples of input/output operations and mathematical calculations.

Uploaded by

ccmcarvila
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

C Programming Quiz and Coding Tasks

The document consists of multiple choice questions, fill-in-the-blank statements, and coding problems related to the C programming language. It covers topics such as syntax, functions, variable types, and basic programming constructs. The coding section includes examples of input/output operations and mathematical calculations.

Uploaded by

ccmcarvila
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Multiple choice questions. Choose ONE correct answer.

1. Who developed the C programming language?


a) Bjarne Stroustrup
b) Dennis Ritchie
c) James Gosling
d) Guido van Rossum

2. What is the correct syntax to include a standard header file


in C?
a) #include file.h
b) include <file.h>
c) #include <file.h>
d) #include "file.h"

3. What does a compiler do?


a) Converts high-level code to machine code
b) Executes the program line by line
c) Interprets the code
d) Debugs the program

4. The function printf() is used for:


a) Taking input
b) Displaying output
c) Declaring variables
d) Allocating memory

5. What is the default return type of main() in C?


a) void
b) int
c) char
d) float

6. The scanf() function requires which symbol to read


variables?
a) *
b) &
c) #
d) %

7. The getchar() function is used to:


a) Read an integer
b) Read a float value
c) Read a character
d) Read a string

8. What is the extension of a C source file?


a) .cpp
b) .java
c) .c
d) .py

9. What is \n used for in C?


a) Newline character
b) Null character
c) Tab space
d) None of the above

10. What is the correct syntax to print a float value with 2


decimal places?
a) printf("%.2d", value);
b) printf("%.2f", value);
c) printf("%2.f", value);
d) printf("%f.2", value);

Fill in the blanks. Write only ONE word in blank.

1. A variable name in C cannot start with a number.


2. The sizeof(int) in C typically returns 4 bytes on a 32-bit
system.
3. A constant in C can be defined using the const keyword or
the #define directive.
4. The while loop executes as long as the given condition is
true.
5. An uninitialized variable in C contains garbage value.
Coding questions. Write code for each problem.
1. printf("Hello Sejong!", text);
2. printf(" # ", text);
printf(" ### ", text);
printf("#####", text);
3. #include <stdio.h>

int main() {
float num;

printf("Enter a floating-point number: ");


scanf("%f", &num);

printf("Result with precision 2: %.2f\n", num);

return 0;
}

4. #include <stdio.h>

int main() {
int number;
int thirdPower;

// Prompt the user to enter a number


printf("Enter an integer: ");
scanf("%d", &number);

// Calculate the third power by multiplying the number by itself three times
thirdPower = number * number * number;

// Print the result


printf("The third power of %d is: %d\n", number, thirdPower);

return 0;
}

5. #include <stdio.h>

int main() {
int number;

// Prompt the user to enter a 5-digit number


printf("Enter a 5-digit number: ");
scanf("%d", &number);

// Input validation (optional but recommended)


if (number < 10000 || number > 99999) {
printf("Invalid input. Please enter a 5-digit number.\n");
return 1; // Indicate an error
}

// Extract the third digit


int thirdDigit = (number / 100) % 10;

// Print the third digit


printf("The third digit of %d is: %d\n", number, thirdDigit);

return 0; // Indicate successful execution


}

6. #include <stdio.h>

int main() {
float celsius, fahrenheit;

// Prompt the user to enter temperature in Celsius


printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);

// Convert Celsius to Fahrenheit using the formula: F = (C * 9/5) + 32


fahrenheit = (celsius * 9.0 / 5.0) + 32.0;

// Print the temperature in Fahrenheit with 1 decimal place precision


printf("Temperature in Fahrenheit: %.1f\n", fahrenheit);

return 0;
}

7. #include <stdio.h>
int main() {
int n;

// Prompt the user to enter a non-negative integer


printf("Enter a non-negative integer N: ");
scanf("%d", &n);

// Handle the base cases


if (n == 0) {
printf("Last two digits of 25^0 is: 01\n");
} else if (n == 1) {
printf("Last two digits of 25^1 is: 25\n");
} else {
// For N >= 2, the last two digits of 25^N are always25
printf("Last two digits of 25^%d is: 25\n", n);
}
return 0;
}

You might also like