Important:
#include <stdio.h> int main(void) { int x = 11; int y = 3; printf("%d\n", x / y); return 0; }
question.c is compiled with dcc on a CSE machine like this:
dcc question.c -o question
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./question
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
#include <stdio.h> int main(int argc, char *argv[]) { printf("%d\n", argc); return 0; }
q2.c is compiled with dcc on a CSE machine like this:
dcc q2.c -o q2
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q2 hello world
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
#include <stdio.h> #include <string.h> int main(void) { char *s = "hello"; char i = strlen(s); printf("%c%d\n", s[0], i); return 0; }
q3.c is compiled with dcc on a CSE machine like this:
dcc q3.c -o q3
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q3
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
#include <stdio.h> int main(void) { int x = 11; int y = 3; printf("%d\n", x % y); return 0; }
question.c is compiled with dcc on a CSE machine like this:
dcc question.c -o question
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./question
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
#include <stdio.h> int main(int argc, char *argv[]) { printf("%s\n", argv[1]); return 0; }
q2.c is compiled with dcc on a CSE machine like this:
dcc q2.c -o q2
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q2 hello world
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
#include <stdio.h> #include <string.h> int main(void) { char *s = "hello"; printf("%d\n", strcmp(s, s)); return 0; }
q3.c is compiled with dcc on a CSE machine like this:
dcc q3.c -o q3
It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:
./q3
What does this program print?
Enter as your answer the output the program produces. Do not enter any extra characters. Do not enter any explanation.
Enter exactly the output the program produces.
If the program prints an error message just write ERROR. Do not enter the exact error message.
Other examples include:
Also see: Practice Questions for the Final Exam (includes many questions for part-1)
The following two files will be available in the directory named "q1":
You need to implement a C function isLeapYear
, in the given file isLeapYear.c
,
that takes a year as an argument and calculates whether that year is a leap year or not. The function must return
1 if the year is a leap yer, 0 otherwise.
int isLeapYear(int year)
For example,
isLeapYear(2018) returns 0 isLeapYear(2000) returns 1 isLeapYear(1900) returns 0
For this question, you need to use the provided file test_isLeapYear.c
to test your function.
Please open the file test_isLeapYear.c
using an available text editor, try to understand how your function is tested.
You can use the following commands to compile and run few tests already provided in the file test_isLeapYear.c
.
Please make sure that you also test your function extensively by adding more test cases in test_isLeapYear.c
.
You will be submitting only one file isLeapYear.c
.
To run the simple tests available in test_isLeapYear.c
, execute the following commands:
$ dcc -o test_isLeapYear isLeapYear.c test_isLeapYear.c $ ./test_isLeapYear
Again, please make sure that you test your function extensively by adding more test cases in test_isLeapYear.c
.
You will be submitting only one file isLeapYear.c
for this question.
Submit your file isLeapYear.c
with the following command, from "q1" directory:
$ submit q1
outliers.c
that reads integer values from standard input until the end of input stream or first unsuccessful read.
The program finds number of values that are outside the range of 5 to 25 (inclusive), and prints the number of such outliers.
Make your program match the examples below exactly.
./outliers Enter number: 12 Enter number: 4 Enter number: 25 Enter number: 15 Enter number: 27 Enter number: Ctrl + D Outliers: 2 ./outliers Enter number: 0 Enter number: 26 Enter number: 5 Enter number: -2 Enter number: Ctrl + D Outliers: 3
When you think your program is working you can use autotest
to run some simple automated tests.
From the directory "q2", run the following command:
./autotest
Please make sure that you test your program extensively by considering more test cases.
You will be submitting only one file outliers.c
for this question.
Submit your file outliers.c
with the following command, from "q2" directory:
$ submit q2
For other examples: see Practice Questions for the Final Exam
The following two files will be available in the directory named "q3":
You need to implement the following function that returns minimum positive
value from a given array a
(of type int
). A value is a positive value
if it is greater than zero. If there are no positive values in a given list, the function should return zero.
int arrayPositiveMin(int a[], int size)
For example,
arrayPositiveMin([4, 2, 9], 3) returns 2 arrayPositiveMin([5, -6, 3 , 20], 4) returns 3 arrayPositiveMin([5, -6, -12 , 5, 0, -2 , 8], 7) returns 5 arrayPositiveMin([-2, -4, -8, -2], 4) returns 0
For this question, you need to use the provided file test_arrayPositiveMin.c
to test your function.
Please open the file test_arrayPositiveMin.c
using your favourite text editor,
try to understand how your function is tested. If you have
any questions, please ask your tutor.
You can use the following commands to compile and run few tests already provided in the file test_arrayPositiveMin.c
.
Please make sure that you also test your function extensively by adding more test cases in test_arrayPositiveMin.c
.
To run the simple tests available in test_arrayPositiveMin.c
, execute the following commands:
$ dcc -o test_arrayPositiveMin arrayPositiveMin.c test_arrayPositiveMin.c $ ./test_arrayPositiveMin
Again, please make sure that you test your function extensively by adding more test cases in test_arrayPositiveMin.c
.
You will be submitting only one file arrayPositiveMin.c
for this question.
Submit your file arrayPositiveMin.c
with the following command, from "q3" directory:
$ submit q3
For other examples: see Practice Questions for the Final Exam
void species_count(char species[], int n_sightings, struct pod sightings[n_sightings], int *n_pods, int *n_whales) {
// REPLACE THIS COMMENT WITH YOUR CODE
// THIS FUNCTION SHOULD NOT CALL SCANF OR PRINTF
// IT SHOULD JUST ASSIGN VALUES to N_PODS AND N_WHALES
*n_pods = 24; // CHANGE ME
*n_whales = 42; // CHANGE ME
}
By the way, the sample solutions for Lab07 are also available (see Labs).
For other examples: see Practice Questions for the Final Exam
The following two questions will be related to the examples discussed in the Lectures on Linked List, and the related lab and tutorial quesrions. You can either use an iterative approach or a recursive approach,
This question will be related to Lab08 exercises. In particular, Exercise-02 that requires you to implement the following function, read Lab08 for more explanation.
void species_count(char species[], struct pod *first_pod, int *n_pods, int *n_whales) {
// REPLACE THIS COMMENT WITH YOUR CODE
// THIS FUNCTION SHOULD NOT CALL SCANF OR PRINTF
// IT SHOULD JUST ASSIGN VALUES to N_PODS AND N_WHALES
*n_pods = 24; // CHANGE ME
*n_whales = 42; // CHANGE ME
}
By the way, the sample solutions for Lab08 are also available (see Labs).
Other examples include:
For other examples: see Practice Questions for the Final Exam
For example, you may need to implement a function similar to one of the following functions (most of them discussed in the lectures/tutorials/labs):
For other examples: see Practice Questions for the Final Exam
Complex programming using any of the features covered in course.
-- end --