0% found this document useful (0 votes)
4 views24 pages

Week 03-01

The document contains a quiz for a programming course (GE23131) focused on C language, with multiple questions testing various programming concepts. Each question includes a task, sample inputs and outputs, and the corresponding C code to solve the problem. The quiz covers topics such as conditional statements, Pythagorean triples, shape identification, the Chinese zodiac, chessboard colors, and calculating the day of the year from a date.
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)
4 views24 pages

Week 03-01

The document contains a quiz for a programming course (GE23131) focused on C language, with multiple questions testing various programming concepts. Each question includes a task, sample inputs and outputs, and the corresponding C code to solve the problem. The quiz covers topics such as conditional statements, Pythagorean triples, shape identification, the Chinese zodiac, chessboard colors, and calculating the day of the year from a date.
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/ 24

REC-CIS

GE23131-Programming Using C-2024


Quiz navigation
Status Finished
1 2 3
Started Monday, 23 December 2024, 5:33 PM
Completed Wednesday, 6 November 2024, 9:49 AM
Show one page at a time
Duration 47 days 7 hours
Finish review
Question 1 Write a program to read two integer values and print true if both the numbers end
Correct with the same digit, otherwise print false. Example: If 698 and 768 are given, program
Marked out of should print true as they both end with 8. Sample Input 1 25 53 Sample Output 1 false
3.00 Sample Input 2 27 77 Sample Output 2 true
Flag question
Answer: (penalty regime: 0 %)
1 #include<stdio.h>
2 int main()
3 ▼ {
4 int a,b;
5 scanf("%d %d",&a,&b);
6 ▼ if(a%10==b%10){
7 printf("true");
8 ▼ }else{
9 printf("false");
10 }
11 }
REC-CIS

Input Expected Got

 25 53 false false 

 27 77 true true 

Passed all tests! 

Question 2
Objective
Correct

Marked out of
5.00 In this challenge, we're getting started with conditional statements.

Flag question

Task

Given an integer, n, perform the following conditional actions:

· If n is odd, print Weird

· If n is even and in the inclusive range of 2 to 5, print Not Weird

· If n is even and in the inclusive range of 6 to 20, print Weird

· If n is even and greater than 20, print Not Weird

Complete the stub code provided in your editor to print whether or not n is weird.
Input Format
REC-CIS

A single line containing a positive integer, n.

Constraints

· 1 < n < 100

Output Format

Print Weird if the number is weird; otherwise, print Not Weird.

Sample Input 0

Sample Output 0

Weird

Sample Input 1

24

Sample Output 1
Not Weird
REC-CIS

Explanation

Sample Case 0: n = 3

n is odd and odd numbers are weird, so we print Weird.

Sample Case 1: n = 24

n > 20 and n is even, so it isn't weird. Thus, we print Not Weird.

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 int main()
3 ▼ {
4 int n;
5 scanf("%d",&n);
6 ▼ if(n%2!=0){
7 printf("Weird");
8 }
9 ▼ else if(n%2==0){
10 ▼ if(n>=2 && n<=5){
11 printf("Not Weird");}
12 ▼ else if(n>=6 && n<=20){
13 printf("Weird");
14 }
15 ▼ else if (n>20){
16 printf("Not Weird");
17 }
18 }
19 }
20
REC-CIS
Input Expected Got

 3 Weird Weird 

 24 Not Weird Not Weird 

Passed all tests! 

Question 3 Three numbers form a Pythagorean triple if the sum of squares of two numbers is
Correct equal to the square of the third. For example, 3, 5 and 4 form a Pythagorean triple,
Marked out of since 3*3 + 4*4 = 25 = 5*5 You are given three integers, a, b, and c. They need not be
7.00 given in increasing order. If they form a Pythagorean triple, then print "yes", otherwise,
Flag question print "no". Please note that the output message is in small letters. Sample Input 1 3 5 4
Sample Output 1 yes Sample Input 2 5 8 2 Sample Output 2 no

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 int main()
3 ▼ {
4 int a,b,c;
5 scanf("%d %d %d",&a,&b,&c);
6 if(a*a+b*b==c*c || b*b+c*c==a*a |
7 ▼ {
8 printf("yes");
9 ▼ }else{
10 printf("no");
11 }
12 }
REC-CIS

Input Expected Got

 3 yes yes 
5
4

 5 no no 
8
2

Passed all tests! 

Finish review
REC-CIS

GE23131-Programming Using C-2024


Quiz navigation
Status Finished
1 2 3
Started Monday, 23 December 2024, 5:33 PM
Completed Wednesday, 27 November 2024, 9:10 AM
Show one page at a time
Duration 26 days 8 hours
Finish review
Question 1

Correct
Write a program that determines the name of a shape from its number of sides. Read
Marked out of
the number of sides from the user and then report the appropriate name as part of a
3.00
meaningful message. Your program should support shapes with anywhere from 3 up to
Flag question
(and including) 10 sides. If a number of sides outside of this range is entered then your
program should display an appropriate error message.

Sample Input 1

Sample Output 1

Triangle

Sample Input 2
7
REC-CIS

Sample Output 2

Heptagon

Sample Input 3

11

Sample Output 3

The number of sides is not supported.

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 ▼ int main(){
3 int n;
4 scanf("%d",&n);
5 ▼ switch(n){
6 case 3:
7 printf("Triangle");
8 break;
9 case 4:
10 printf("Square");
11 break;
12 case 5:
13 printf("Pentagon");
14 break;
15 case 6:
16 printf("Hexagon");
17 break;
18 case 7:
19 printf( Heptagon );
20 break;
REC-CIS 21 case 8:
22 printf("Octagon");
23 break;
24 case 9:
25 printf("Nonagon");
26 break;
27 default:
28 printf("The number of sides i
29 }
30
31 }

Input Expected Got

 3 Triangle Triangle 

 7 Heptagon Heptagon 

 11 The number of sides is not The number of sides is not 


supported. supported.

Passed all tests! 

Question 2
The Chinese zodiac assigns animals to years in a 12-year cycle. One 12-year cycle is
Correct
shown in the table below. The pattern repeats from there, with 2012 being another
Marked out of
year of the Dragon, and 1999 being another year of the Hare.
5.00

Flag question
Year Animal

2000 Dragon
2001 Snake
REC-CIS
2002 Horse

2003 Sheep

2004 Monkey

2005 Rooster

2006 Dog

2007 Pig
2008 Rat

2009 Ox

2010 Tiger

2011 Hare

Write a program that reads a year from the user and displays the animal associated
with that year. Your program should work correctly for any year greater than or equal
to zero, not just the ones listed in the table.

Sample Input 1

2004

Sample Output 1

Monkey

Sample Input 2

2010
REC-CIS
Sample Output 2

Tiger

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 ▼ int main(){
3 int year;
4 scanf("%d",&year);
5 if(year%12 ==8)
6 printf("Dragon");
7 else if(year%12 ==9)
8 printf("Snake");
9 else if(year%12 ==10)
10 printf("Horse");
11 else if(year%12 ==11)
12 printf("Sheep");
13 else if(year%12 ==0)
14 printf("Monkey");
15 else if(year%12 ==1)
16 printf("Rooster");
17 else if(year%12 ==2)
18 printf("Dog");
19 else if(year%12 ==3)
20 printf("Pig");
21 else if(year%12 ==4)
22 printf("Rat");
23 else if(year%12 ==5)
24 printf("Ox");
25 else if(year%12 ==6)
26 printf("Tiger");
27 else
28 printf("Hare");
29 }
REC-CIS
Input Expected Got

 2004 Monkey Monkey 

 2010 Tiger Tiger 

Passed all tests! 

Question 3
Positions on a chess board are identified by a letter and a number. The letter identifies
Correct
the column, while the number identifies the row, as shown below:
Marked out of
7.00

Flag question

Write a program that reads a position from the user. Use an if statement to determine if
the column begins with a black square or a white square. Then use modular arithmetic to
report the color of the square in that row. For example, if the user enters a1 then your
program should report that the square is black. If the user enters d5 then your program
should report that the square is white. Your program may assume that a valid position will
always be entered. It does not need to perform any error checking.

Sample Input 1
REC-CIS
a1

Sample Output 1

The square is black.

Sample Input 2

d5

Sample Output 2

The square is white.

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 ▼ int main(){
3 int num,sum;
4 char alpha;
5 scanf("%c%d",&alpha,&num);
6 sum = alpha + num;
7 if(sum%2==0)
8 printf("The square is black.");
9 else
10 printf("The square is white.");
11
12 }
REC-CIS

Input Expected Got

 a 1 The square is black. The square is black. 

 d 5 The square is white. The square is white. 

Passed all tests! 

Finish review
REC-CIS

GE23131-Programming Using C-2024


Quiz navigation
Status Finished
1 2 3
Started Monday, 23 December 2024, 5:33 PM
Completed Tuesday, 3 December 2024, 2:14 PM
Show one page at a time
Duration 20 days 3 hours
Finish review
Question 1
Some data sets specify dates using the year and day of year rather than the year,
Correct
month, and day of month. The day of year (DOY) is the sequential day number starting
Marked out of
with day 1 on January 1st.
3.00

Flag question
There are two calendars - one for normal years with 365 days, and one for leap years
with 366 days. Leap years are divisible by 4. Centuries, like 1900, are not leap years
unless they are divisible by 400. So, 2000 was a leap year.

To find the day of year number for a standard date, scan down the Jan column to find
the day of month, then scan across to the appropriate month column and read the day
of year number. Reverse the process to find the standard date for a given day of year.

Write a program to print the Day of Year of a given date, month and year.

Sample Input 1

18
6
REC-CIS
2020

Sample Output 1

170

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 int main()
3 ▼ {
4 int d,m,y,feb;
5 scanf("%d %d %d",&d,&m,&y);
6 if((y%100==0&&y%400) || (y%4==0))
7 feb=29;
8 else
9 feb=28;
10 switch(m)
11 ▼ {
12 case 1:
13 printf("%d",d);
14 break;
15 case 2:
16 printf("%d",31+d);
17 break;
18 case 3:
19 printf("%d",31+feb+d);
20 case 4:
21 printf("%d",31+feb+31+d);
22 break;
23 case 5:
24 printf("%d",31+feb+31+30+d);
25 break;
26 case 6:
27 printf("%d",31+feb+31+30+31+d);
28 break;
29 case 7:
30 printf("%d",31+feb+31+30+31+30+d)
REC-CIS 31 break;
32 case 8:
33 printf("%d",31+feb+31+30+31+30+31
34 break;
35 case 9:
36 printf("%d",31+feb+31+30+31+30+31
37 break;
38 case 10:
39 printf("%d",31+feb+31+30+31+30+31
40 break;
41 case 11:
42 printf("%d",31+feb+31+30+31+30+31
43 break;
44 case 12:
45 printf("%d",31+feb+31+30+31+30+31
46 break;
47 }
48 }
49

Input Expected Got

 18 170 170 
6
2020

Passed all tests! 

Question 2
Suppandi is trying to take part in the local village math quiz. In the first round, he is
Correct
asked about shapes and areas. Suppandi, is confused, he was never any good at math.
Marked out of
And also, he is bad at remembering the names of shapes. Instead, you will be helping
5.00
him calculate the area of shapes.
Flag question
REC-CIS
· When he says rectangle he is actually referring to a square.

· When he says square, he is actually referring to a triangle.

· When he says triangle he is referring to a rectangle

· And when he is confused, he just says something random. At this point, all you
can do is say 0.

Help Suppandi by printing the correct answer in an integer.

Input Format

· Name of shape (always in upper case R à Rectangle, S à Square, T à Triangle)

· Length of 1 side

· Length of other side

Note: In case of triangle, you can consider the sides as height and length of base

Output Format

· Print the area of the shape.

Sample Input 1

10

20
Sample Output 1
REC-CIS

200

Sample Input 2

S
30

40

Sample Output 2

600

Sample Input 3

10

10

Sample Output 3

100

Sample Input 4
REC-CIS
G

Sample Output 4

Sample Input

10

Sample Output 4

Explanation:

· First is output of area of rectangle

· Then, output of area of triangle

· Then output of area square

· Finally, something random, so we print 0


Answer: (penalty regime: 0 %)
REC-CIS
1 #include<stdio.h>
2 int main()
3 ▼ {
4 int a,b;
5 char c;
6 scanf("%c %d %d",&c,&a,&b);
7 switch(c)
8 ▼ {
9 case 'R':
10 printf("%d",a*b);
11 break;
12 case 'S':
13 printf("%.0f",(0.5)*a*b);
14 break;
15 case 'T':
16 printf("%d",a*b);
17 break;
18 default:
19 printf("0");
20 }
21 }

Input Expected Got

 T 200 200 
10
20

 S 600 600 
30
40

 B 0 0 
2
11

 R 300 300 
10
30
REC-CIS
 S 1000 1000 
40
50

Passed all tests! 

Question 3 Superman is planning a journey to his home planet. It is very important for him to
Incorrect know which day he arrives there. They don't follow the 7-day week like us. Instead, they
Marked out of follow a 10-day week with the following days: Day Number Name of Day 1 Sunday 2
7.00 Monday 3 Tuesday 4 Wednesday 5 Thursday 6 Friday 7 Saturday 8 Kryptonday 9
Flag question Coluday 10 Daxamday Here are the rules of the calendar: • The calendar starts with
Sunday always. • It has only 296 days. After the 296th day, it goes back to Sunday. You
begin your journey on a Sunday and will reach after n. You have to tell on which day
you will arrive when you reach there.

Input format: •

Contain a number n (0 < n)

Output format: Print the name of the day you are arriving on

Example Input

Example Output

Kryptonday

Example Input

Example Output Monday

Answer: (penalty regime: 0 %)


1 #include<stdio.h>
2 int main()
3 ▼ {
4 int n;
REC-CIS 5 scanf("%d",&n);
6 int day =n%10;
7 for(int i=0;i<i;i++)
8 ▼ {
9 switch
10 }
11 }

Syntax Error(s)
__tester__.c: In function ‘main’:
__tester__.c:7:18: error: self-comparison always evaluates to false [-
Werror=tautological-compare]
7 | for(int i=0;i<i;i++)
| ^
__tester__.c:10:5: error: expected ‘(’ before ‘}’ token
10 | }
| ^
| (
__tester__.c:6:9: error: unused variable ‘day’ [-Werror=unused-variable]
6 | int day =n%10;
| ^~~
cc1: all warnings being treated as errors

Finish review
REC-CIS

You might also like