NPTEL Introduction To Programming In C Assignment 2 Answers 2022

NPTEL Introduction To Programming In C Assignment 2

Are you looking for the Answers to NPTEL Introduction To Programming In C Assignment 2? This article will help you with the answer to the National Programme on Technology Enhanced Learning (NPTEL) Course “NPTEL Introduction To Programming In C Assignment 2″

What is Introduction To Programming In C?

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. 

CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the average of best 6 assignments out of the total 8 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.

Below you can find the answers for NPTEL Introduction To Programming In C Assignment 2

Assignment No.Answers
Introduction To Programming In C Assignment 1 Click Here
Introduction To Programming In C Assignment 2 Click Here
Introduction To Programming In C Assignment 3 Click Here
Introduction To Programming In C Assignment 4 Click Here
Introduction To Programming In C Assignment 5 Click Here
Introduction To Programming In C Assignment 6 Click Here
Introduction To Programming In C Assignment 7 Click Here
Introduction To Programming In C Assignment 8 Click Here

NPTEL Introduction To Programming In C Assignment 2 Answers:-

Q1. In this assignment, you will be given an NxN matrix. You have to determine whether the matrix is a upper triangular or lower triangular matrix or both or not a triangular matrix. 

The diagonal of the matrix M of size NxN is the set of entries M(0,0), M(1,1), M(2,2), …, M(N,N).    A matrix is upper triangular if every entry below the diagonal is 0. For example,   1 1 1 0 0 1 0 0 2 is an upper triangular matrix. (The diagonal itself, and the entries above can be zeroes or non-zero integers.) 

A matrix is lower triangular if every entry above the diagonal is 0. For example,  2 0 0 3 1 0 4 2 2 is a lower triangular matrix  (The diagonal itself, and the entries below can be zeroes or non-zero integers.) .    A matrix is not a triangular matrix if it is neither a upper triangular nor a  lower triangular.   You may not use arrays for this program.   Input First, you will be given N, which is the size of the matrix.   Then you will be given N rows of integers, where each row consists of N integers separated by spaces.   

Output If the input matrix is lower triangular, then print -1.
If the input matrix is upper triangular, then print 1.
If the input matrix is both lower and upper triangular, then print 2.
If the input matrix is not a triangular matrix, then print 0. Kindly do not use arrays in the code.

Code:-

#include<stdio.h>
int main() {
  
  int N, val, lower = 1, upper = 1;
  scanf("%d", &N);
  
  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      scanf("%d", &val);
      
      if(i>j && val!=0)
        upper = 0;
      if(i<j && val!=0)
        lower = 0;   
    }
  }
  
  if((upper == 1) && (lower == 1))
    printf("2");
  else if(upper == 1)
    printf("1");
  else if(lower == 1)
    printf("-1");
  else
    printf("0");
    
  return 0;
}

Q2. You are given a sorted(either in the increasing or in the decreasing order) sequence of positive numbers, ending with a -1. You can assume that there are atleast three numbers before the ending -1. 
Note : -1 is not a part of input. It only signifies that input has ended.

Let us call the sequence x0  x1 … xn -1.

You have to output 1 if there are at least three distinct numbers in the sequence.
otherwise output 0
Kindly do not use arrays in the code.

Code:-

#include<stdio.h>

int main() {
  int num, count = 0;
  scanf("%d", &num);
  
  while(num!=-1) {
    int x, y;
    x = num;
    scanf("%d", &num);
    y = num;
    if((x!=y) && (num!=-1))
      count++;
  }
  if(count >= 2)
    printf("1");
  else
    printf("0");
  
  return 0;
}

???? Next Week Assignment Answers????

quizxp telegram

Q3. You are given a non-negative sequence of numbers, ending with a -1. You can assume that there are at least two numbers before the ending -1. 
Note : -1 is not a part of input. It only signifies that input has ended.
Let us call the sequence x0  x1 … xn -1.
You have to output the second largest element of the sequence. if there is no second largest element in the sequence then output 0.

Kindly do not use arrays in the code.

Code:-

#include<stdio.h>

int main() {
  int num, num1, num2;
  scanf("%d", &num);
  num1 = num;
  num2 = 0;
  while(num!=-1) {
    scanf("%d", &num);
    if(num1 < num) {
      num2 = num1;
      num1 = num;
    }
  }
  if(num2 != 0)
    printf("%d", num2);
  else
    printf("0");
  
  return 0;
}

For other courses answers:- Visit

For Internship and job updates:- Visit

Disclaimer: We do not claim 100% surety of answers, these answers are based on our sole knowledge, and by posting these answers we are just trying to help students, so we urge do your assignment on your own.

if you have any suggestions then comment below or contact us at [email protected]

If you found this article Interesting and helpful, don’t forget to share it with your friends to get this information.