Problem Solving Through Programming In C Week 7

Session: JAN-APR 2023

Course Name: Problem Solving Through Programming In C

Course Link: Click Here

These are Problem Solving Through Programming In C Assignment 7 Answers


Q1. The searching operation in an array is done using
a) Key and index
b) Only key
c) Only index
d) None of these

Answer: a) Key and index


Q2. Find the output of the following C program.
a) fellows
b) h
c) fello
d) Compiler error

Answer: a) fellows


These are Problem Solving Through Programming In C Assignment 7 Answers


Q3. What will be the output?
a) n1=18, n2=17
b) n1=18, n2=18
c) n1=17, n1=17
d) n1=17, n2=18

Answer: a) n1=18, n2=17


Q4. Consider the following C program segment:
a) gnirts
b) gnirt
c) string
d) no output is printed

Answer: d) no output is printed


These are Problem Solving Through Programming In C Assignment 7 Answers


Q5. What will be the value of ā€˜iā€™ after the execution of the C code given below?
a) 0
b) 1
c) -1
d) None

Answer: a) 0


Q6. If the starting address of an float array Arr[10][10] is 2000, what would be the memory address of the element Arr[5][6]? (float takes 4 bytes of memory)
a) 2268
b) 2120
c) 2224
d) 2144

Answer: c) 2224


These are Problem Solving Through Programming In C Assignment 7 Answers


Q7. In C, the placement of elements of a two dimensional array is
a) Row wise
b) Column wise
c) Diagonal wise
d) Bottom to top wise

Answer: d) Bottom to top wise


Q8.

image 22

Answer: 321004


These are Problem Solving Through Programming In C Assignment 7 Answers


Q9. What will be the output?
a) The string is empty
b) The string is not empty
c) Error
d) None of the above

Answer: b) The string is not empty


Q10. What is the output of the following C code?
a) Compilation error
b) 7
c) 1
d) 2

Answer: a) Compilation error


These are Problem Solving Through Programming In C Assignment 7 Answers


Problem Solving Through Programming In C Programming Assignment

Question 1

Write a C Program to Count Number of Uppercase and Lowercase Letters in a given string. The given string may be a word or a sentence.

Solution:

int i = 0;
   while (ch[i] != '\0') {
      if (ch[i] >= 'A' && ch[i] <= 'Z')
         upper++;
      if (ch[i] >= 'a' && ch[i] <= 'z')
         lower++;
      i++;
   }

Question 2

Write a C program to find the sum of all elements of each row of a matrix.
   Example: For a matrix  4 5 6
                                        6 7 3
                                        1 2 3
  The output will be 
  15
  16
   6

Solution:

int sum;
    for(i=0;i< r;i++)
    {
        sum=0;      
        for(j=0;j< c;j++)
        {  
            sum+=  matrix[i][j];
        }
        printf("%d\n",sum);
    }
}

These are Problem Solving Through Programming In C Assignment 7 Answers


Question 3

Write a C program to find subtraction of two matrices i.e. matrix_A – matrix_B=matrix_C.
 If the given martix are 
 2 3 5     and  1 5 2    Then the output will be  1 -2 3
 4 5 6             2 3 4                                           2 2 2
 6 5 7             3 3 4                                           3 2 3
 The elements of the output matrix are separated by one blank space 

Solution:

for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            matrix_C[i][j] = matrix_A[i][j] - matrix_B[i][j];
        }
    }
     for(i=0; i<row; i++)
    {
        for(j=0; j<col; j++)
        {
            printf("%d ", matrix_C[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Question 4

Write a C program to print lower triangle of a square matrix.
For example the output of a given matrix 
2 3 4     will be       2 0 0
5 6 7                      5 6 0
4 5 6                      4 5 6

Solution:

for(i=0; i<r; i++)
{
	for(j=0; j<r; j++)
           {
		if(i>=j)
		printf("%d ", matrix[i][j]);
		else
			printf("%d ", 0);
           }
	   printf("\n");
}
return 0;
}

These are Problem Solving Through Programming In C Assignment 7 Answers

More Weeks of Problem Solving Through Programming In C: Click Here

More Nptel courses: https://progiez.com/nptel


Session: JULY-DEC 2022

Course Name: Problem Solving Through Programming In C NPTEL

Link of course: Click Here

These are Problem Solving Through Programming In C Assignment 7 Answers


1) Which of the following statement/s are false?
I. Array elements are stored in memory in contiguous locations.
II. An integer array always terminates with ‘\0’ (NULL).

a)l
b) ll
c) Both I and II
d) None

Answer: b) ll


2) If two strings are identical, then strcmp() function returns
a) 1
b) 0
c)-1
d) None of these

Answer: b) 0


3) Which of the following function is more appropriate for reading in a multi word string?
a) scanf()
b) gets()
c) printf()
d) puts()

Answer: b) gets()


These are Problem Solving Through Programming In C Assignment 7 Answers


4) What will be printed after execution of the following code?

Answer: 40


5) What will be the output of the program?
a) Array
b) Array String
c) Array\0String
d) Compilation error

Answer: a) Array


6) What will be the output?
a) Programming
b) Language
c) Programming Language
d) Language Programming

Answer: c) Programming Language


These are Problem Solving Through Programming In C Assignment 7 Answers


7) What will be the output?
a) n1= 8, n2=8
b) n1=9, n2=9
c) n1=8, n2=9
d) n1=9, n2=8

Answer: d) n1=9, n2=8


8) What will be the output?

Answer: 720


9) What will be the output?
a) assignment
b) tnemngissa
c) nothing will be printed
d) tttttttttt

Answer: c) nothing will be printed


These are Problem Solving Through Programming In C Assignment 7 Answers


10) What will be the output?
a) Two strings are equal
b) Two strings are not equal
c) Would not print anything
d) Compilation error

Answer: c) Would not print anything


Assignment

Question 1
Write a C program to find the sum of all elements of each row of a matrix.
Example:
For a matrix
 4 5 6
 6 7 3
 1 2 3
 The output will be
 15
 16
 6

Solution:

//Code

These are Problem Solving Through Programming In C Assignment 7 Answers


Question 2
Write a C program to find subtraction of two matrices i.e, matrix_A ā€“ matrix_B=matrix_C.
If the given martix are:
 2 3 5 and 1 5 2
Then the output will be 1 -2 3
 4 5 6        2 3 4                                          2 2 2
 6 5 7        3 3 4                                          3 2 3

Solution:

//Code

These are Problem Solving Through Programming In C Assignment 7 Answers


Question 3
Write a C program to print lower triangle of a square matrix.
For example the output of a given matrix
2 3 4 will be 2 0 0
5 6 7             5 6 0
4 5 6             4 5 6

Solution:

//Code

These are Problem Solving Through Programming In C Assignment 7 Answers


Question 4
Write a C program to print Largest and Smallest Word from a given sentence. If there are two or more words of same length, then the first one is considered. A single letter in the sentence is also consider as a word.

Solution:

//Code

These are Problem Solving Through Programming In C Assignment 7 Answers

More NPTEL Solution: https://progiez.com/nptel


* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.


More from PROGIEZ

These are Problem Solving Through Programming In C Assignment 7 Answers