NPTEL Introduction to programming in C Assignment 2 Answers 2024

NPTEL Introduction to programming in C Assignment 2 Answers 2024

Hello learners In this article we are going to discuss NPTEL Introduction to programming in C Assignment 2 Answers. All the Answers provided below to help the students as a reference, You must submit your assignment with your own knowledge and use this article as reference only.

About the course:-

This is a course in programming in C. No prior programming experience is assumed; however, mathematical maturity at the level of a second year science or engineering undergraduate is assumed. We emphasize solving problems using the language, and introduce standard programming techniques like alternation, iteration and recursion. We will briefly glimpse the basics of software engineering practices like modularization, commenting, and naming conventions which help in collaborating and programming in teams. 

NPTEL Introduction to programming in C Assignment 2 Answers 2024:

1. You are given a sequence of bits (1’s and 0’s).
The sequence is said to have even parity if and only if the number of 1’s in the sequence if even.

Write a C program to that outputs 1 if the sequence has even parity and 0 otherwise.

Input

A sequence of bits (0’s and 1’s) ending with a -1.
(Note : -1 is not a part of input. It only signifies that input has ended)

Output

1 if the number of ones in the sequence is even.
0 if the number of ones in the sequence is odd.

Answer :- Will update answers soon and update on our telegram channel so Join Click Here

2.  You are given sequence of non-negative integers, sorted in the non decreasing order.
That is if the sequence is a1,a2,…,an,then  aiai+1 for all i from 1 to n-1.

You can assume that are at least two numbers in the sequence.

Write a C program to output the number of distinct elements in the sorted sequence.

Input

A non decreasing sorted sequence of non-negative integers, ending with a -1.
(Note : -1 is not a part of input. It only signifies that input has ended)

Output

The number of distinct elements in the sequence.

Answer :-

3. Count the Number of 0’s Between the First and Last 1

You are given a binary sequence.

Write a C program to count the number of 0’s between the first and last 1 in the sequence.

Input

A sequence of bits (0’s and 1’s) ending with a -1.
(Note : -1 is not a part of input. It only signifies that input has ended)

Output

The number of 0’s Between the First and Last 1 in the sequence.

Note : Make no assumptions about the data in the sequence.
For instance if there is no starting and ending 1 ( say the sequence is all 0), you have to output 0. 

Answer :-