NPTEL » Introduction To Programming In C
Subscribe to our YouTube Channel : Swayam Solver
Week 3: Assignment 3 - Question 1
Due on 2022-03-17, 23:59 IST
Write a C function to find the kth occurrence of an odd integer in a sequence of non-negative integers, and then call your function from main.
Your function should be according to the following declaration:
int find_odd(int k);
Input
You are given the input in two lines:
The first line contains a positive integer k.
In the second line, you will be given a sequence of numbers.
You have to find the kth occurrence of n in the sequence below.
In the second line, you will be given a sequence of numbers.
You have to find the kth occurrence of n in the sequence below.
The second line consists of a sequence of non-negative integers,
terminated with a -1. The -1 is not part of the sequence.
Output
If there are k odd numbers in the sequence, then output the kth
occurrence of odd in the sequence. Otherwise, output -1.
Sample Input
2
1 1 3 2 3 4 1 -1
Sample Output
1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
2 4 6 1 7 -1 | 7 | 7 | Passed |
Test Case 2 | 3
2 4 6 18 -1 | -1 | -1 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Week 3: Assignment 3 - Question 2
Due on 2022-03-17, 23:59 ISTIn this question, you have to output the "moving average" of asequence of non-negative numbers. The moving average is the sequenceof averages of the last 2 entries. For the first number, no averageis output.
For example, if the sequence of numbers is
a1, a2, a3, a4, a5
then the 2-moving average is
(a1+a2)/2, (a2+a3)/2, (a3+a4)/2, (a4+a5)/2
Input-----
The input is a sequence of non-negative floating point numbers,terminated by a -1. The -1 is not part of the sequence. There will beat least 3 numbers in the sequence.
Output--------------------------------------------------------------------------------------------You have to output the moving average of the sequence. The outputshould be printed correct to one digit after the decimal.
Sample Input 1-------------------------------------1 2 3 -1
Sample Output 1------------------------- 1.5 2.5
Public Test Cases Input Expected Output Actual Output Status Test Case 1 4 6 2 -1
5.0 4.0
5.0 4.0
Passed
In this question, you have to output the "moving average" of a
sequence of non-negative numbers. The moving average is the sequence
of averages of the last 2 entries. For the first number, no average
is output.
For example, if the sequence of numbers is
a1, a2, a3, a4, a5
then the 2-moving average is
(a1+a2)/2, (a2+a3)/2, (a3+a4)/2, (a4+a5)/2
Input
-----
The input is a sequence of non-negative floating point numbers,
terminated by a -1. The -1 is not part of the sequence. There will be
at least 3 numbers in the sequence.
Output
--------------------------------------------------------------------------------------------
You have to output the moving average of the sequence. The output
should be printed correct to one digit after the decimal.
Sample Input 1
-------------------------------------
1 2 3 -1
Sample Output 1
-------------------------
1.5 2.5
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 6 2 -1 | 5.0 4.0 | 5.0 4.0 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Week 3: Assignment 3 - Question 3
Due on 2022-03-17, 23:59 ISTWrite a C program to list all the factorial numbers less than or equalto an input number n.
A number N is called a factorial number if it is the factorial of apositive integer. For example, the first few factorial numbers are
1, 2, 6, 24, 120, ...
*Note* - We do not list the factorial of 0.
Input-----A positive integer, say n.
Output------All factorial numbers less than or equal to n.
Public Test Cases Input Expected Output Actual Output Status Test Case 1 4
1 2
1 2
Passed
Test Case 2 30
1 2 6 24
1 2 6 24
Passed
Write a C program to list all the factorial numbers less than or equal
to an input number n.
A number N is called a factorial number if it is the factorial of a
positive integer. For example, the first few factorial numbers are
1, 2, 6, 24, 120, ...
*Note* - We do not list the factorial of 0.
Input
-----
A positive integer, say n.
Output
------
All factorial numbers less than or equal to n.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 | 1 2 | 1 2 | Passed |
Test Case 2 | 30 | 1 2 6 24 | 1 2 6 24 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Watch the video to see the program in motion.
This will help the creator to continue making quality content...
Have a great day !
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.