Please Subscribe Guys.
Assignment 2 ->Question1:
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.
IF YOU NEED EXPLANATION YOU CAN COMMENT .
PROGRAM:
#include<stdio.h>
int main()
{
int n,u=0,l=0,t=0,m=0,d=0;
scanf("%d",&n);
int A[n][n];
m=n-1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&A[i][j]);
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i!=j)
{
if(A[i][j]==0)
t++;
}
if(i>j)
{
if(A[i][j]==0)
u++;
}
if(i<j)
{
if(A[i][j]==0)
l++;
}
}
}
if(t==2*n)
printf("2");
else if(l==n)
printf("-1");
else if(u==n)
printf("1");
else
printf("0");
return 0;
}
Assignment 2 ->Question2:
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 atleast three distinct numbers in the sequence.
otherwise output 0
PROGRAM:
#include<stdio.h>
int main()
{
int a[100],b[100],i=-1,n=0,k=1;
do
{
i++;
scanf("%d",&a[i]);
}while(a[i]!=-1);
for(int j=0;a[j]!=-1;j++)
{ b[j]=a[j];
n++;}
for(int j=1;j<n;j++)
{
if(b[j]!=b[j-1])
k++;
}
if(k==n)
printf("1");
else
printf("0");
return 0;
}
WEEK-0 :INTRODUCTION TO PROGRAMMING IN C
CLICK ON BELOW LINK FOR ASS 2-QUESTION 3.
<<CLICK HERE FOR WEEK 0:ASSIGNMENT 2-> QUESTION 3>>
PLEASE SUBSCRIBE OUR CHANNEL.
<CLICK HERE>
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
CLICK ON BELOW LINK FOR ASS 2-QUESTION 3.
<<CLICK HERE FOR WEEK 0:ASSIGNMENT 2-> QUESTION 3>>
PLEASE SUBSCRIBE OUR CHANNEL.
<CLICK HERE>
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
Assignment 2 (Question 1) Triangular matrix we need to without using array.
ReplyDelete