Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

Introduction To Programming In C Week 3 : Assignment 3 Answers | Jan-2022 | NPTEL | Swayam

 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. 

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
Your last recorded submission was on 2022-03-15, 07:17 IST
Select the Language for this assignment. 
1
#include <stdio.h>
int find_odd(int k);
void main()
{
    int k;
    scanf("%d",&k);
    printf("%d",find_odd(k));
  
}
int find_odd(int k){
  int x,cnt=0, flag=1;
  scanf("%d",&x);
    while(x!=-1)
    {
          if(x%2!=0)
                ++cnt;
          if(cnt==k)
          { return x;
          }
      scanf("%d",&x);
    }
  if (flag)
    return -1;      }
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
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 IST
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
Your last recorded submission was on 2022-03-15, 07:19 IST
Select the Language for this assignment. 
1
#include <stdio.h>
void main()
{
int count=1;
float x0,x1;
   
    scanf("%f",&x0);
    while(x0!=-1)
    {
          scanf("%f",&x1);
          if(x1!=-1 && count)
            printf("%.1f",(x0+x1)/2);
          if(x1!=-1 && !count)
            printf(" %.1f",(x0+x1)/2);
      count=0;
      x0=x1;
    }
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
4 6 2 -1
5.0 4.0
5.0 4.0
Passed



Private Test cases used for EvaluationStatus
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 IST
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.
Your last recorded submission was on 2022-03-15, 07:20 IST
Select the Language for this assignment. 
1
#include <stdio.h>
void main()
{
int n,i,fact;
   
    scanf("%d",&n);
    for(i=1;;++i)
    {     fact=1;
          int num=i;
          while(num)
            fact=fact*num--;
            if(i==1)
              printf("%d", fact);
            else if(fact<=n)
              printf(" %d",fact);
            else break;
    }
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
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 EvaluationStatus
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.


Please Subscribe to our YouTube Channel :  Swayam Solver

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.