Problem Solving Through Programming In C Week 5

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 5 Answers


Q1. “continue” statement in C is used
a) to continue to the next line of code
b) to debug
c) to stop the current iteration and begin the next iteration from the beginning
d) None of the above are true

Answer: c) to stop the current iteration and begin the next iteration from the beginning


Q2. The operators << and >> are
a) Relational operator
b) Logical operator
c) Assignment operator
d) Bitwise shift operator

Answer: d) Bitwise shift operator


These are Problem Solving Through Programming In C Assignment 5 Answers


Q3. Compute the printed value of i of the C program given below
a) 4,5
b) 4,4
c) 5,5
d) 0,0

Answer: c) 5,5


Q4. How many times ‘Hello’ will be printed while executing the below C code?
a) 4 times
b) 20 times
c) 5 times
d) no print

Answer: c) 5 times


These are Problem Solving Through Programming In C Assignment 5 Answers


Q5. What is the output of the following C code?
a) True
b) False
c) Both ‘True’ and ‘False’
d) Compilation error

Answer: c) Both ‘True’ and ‘False’


Q6. Find the output of the following C program
a) 0
b) 1
c) No output
d) Compilation error

Answer: d) Compilation error


These are Problem Solving Through Programming In C Assignment 5 Answers


Q7. How many times the ‘Hello” will be printed in the below C code?
a) 1 time
b) 10 times
c) 11 times
d) Compilation error

Answer: a) 1 time


Q8. How many times Hello will be printed in the below C code?
a) 10 times
b) 5 times
c) 6 times
d) Infinite times

Answer: c) 6 times


These are Problem Solving Through Programming In C Assignment 5 Answers


Q9. ‘What will be the output?
a) 1
b) 2
c) 3
d) Error

Answer: b) 2


Q10. What is the output of the following C program?
a) 5
b) 10
c) No output
d) Compilation error

Answer: c) No output


These are Problem Solving Through Programming In C Assignment 5 Answers


Problem Solving Through Programming In C Programming Assignment

Question 1

Write a C program to count total number of digits of an Integer number (N).

Solution:

int temp, count; 
count=0;
    temp=N;
    while(temp>0)
	{
        count++;
        temp/=10;
    }
printf("The number %d contains %d digits.",N,count);
}

Question 2

Write a C program to check whether the given number(N) can be expressed as Power of Two (2) or not. For example 8 can be expressed as 2^3.

Solution:

int temp, flag;
    temp=N;
    flag=0;
    while(temp!=1)
    {
        if(temp%2!=0){
            flag=1;
            break;
        }
        temp=temp/2;
    }
    if(flag==0)
printf("%d is a number that can be expressed as power of 2.",N);
    else
printf("%d cannot be expressed as power of 2.",N);
}

These are Problem Solving Through Programming In C Assignment 5 Answers


Question 3

Write a C program to find sum of following series where the value of N (odd integer number) is taken as input
123252+….+n2?

Solution:

for (i = 1; i <= n; i += 2) {
      sum += i * i;
   }
    printf("Sum=%d\n", sum);

    return 0;
}

Question 4

Write a C program to print the following Pyramid pattern upto Nth row. Where N (number of rows to be printed) is taken as input.
For example when the value of N is 5 the pyramid will be printed as follows
*****
****
***
**
*

Solution:

int i,j;
for(i=N; i>0; i--)
  {
  for(j=0;j<i;j++)
    {
    printf("*");
    }
  printf("\n");
  } 
}

These are Problem Solving Through Programming In C Assignment 5 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 5 Answers


Q1) What will be the output?
a) 10 9 8 7 6 5 4 3 2 1
b) 1 2 3 4 5 6 7 8 9 10
c) No output
d) None of the above statements are correct

Answer: c) No output


Q2) Which of the following is not an infinite loop?
a) for(; ; )
b) for(x=0; x<=10)
c) while(1)
d) while(0)

Answer: d) while(0)


Q3) Consider the following and identify the false statement(s)?
i) ‘do-while’ loop must be terminated by a semi colon.
ii) ‘do-while’ loop is always an infinite loop.
iii) Even if the condition is false, the ‘do-while’ loop executes once.
iv) ‘do-while’ loop is an entry-controlled loop.

Answer: (ii), (iv)


Q4) Compute the printed value of ‘m’ and ‘n’ of the C program given below?
a) 5,7
b) 5,5
c) 7,7
d) 0,0

Answer: c) 7,7


These are Problem Solving Through Programming In C Assignment 5 Answers


Q5) What should be in the place of so that except i=8, rest of the values of i (as defined in the ‘for’ loop : i=0 to i=19) will be printed?
a) break
b) continue
c) switch
d) exit

Answer: b) continue


Q6) What will be the output?
a) NPTEL
b) IIT/IISc
c) NPTELSWAWAMIIT/IISC
d)Compilation error

Answer: c) NPTELSWAWAMIIT/IISC


Q7) What will be the output?
a) 1,3
b) 1,3 3,1
c) 1,3 2,2 3,1
d) 0,0

Answer: c) 1,3 2,2 3,1


These are Problem Solving Through Programming In C Assignment 5 Answers


Q8) What will be the output of the program?
a) 4 will print 1 times
b) 4 will print 3 times
c) 4 will print 4 times
d) No output

Answer: b) 4 will print 3 times


Q9) For the C program given below, if the input given by the user is 7. What will be shown on the output window?
a) The number is odd
b) The number is prime
c) The number is odd
d) The number is prime Syntax Error

Answer: b) The number is prime


Q10) What will be the output?
a) 0123456789 11 12…..infinite times
b) 123456789 11 12….infinite times
c) Won’t print anything
d) Error

Answer: c) Won’t print anything


These are Problem Solving Through Programming In C Assignment 5 Answers


Programming Assignment Answers

Question 1
Write a C program to count total number of digits of an Integer number (N).

Solution:

#include <stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
    int temp, count;
    count=0;
    temp=N;
    while(temp>0)
    {
     	count++;
     	temp/=10;
    }
    printf("The number %d contains %d digits.",N,count);
}

These are Problem Solving Through Programming In C Assignment 5 Answers


Question 2
Write a C program to find sum of following series where the value of N is taken as input
1+ 1/2 + 1/3 + 1/4 + 1/5 + .. 1/N

Solution:

#include < stdio.h >
int main()
{
    int N;
    float sum = 0.0;
    scanf("%d",&N);
    int i;
    for(i=1;i < = N;i++)
    {
  	    sum = sum + ((float)1/(float)i);
    }
    printf("Sum of the series is: %.2f\n",sum);
}

These are Problem Solving Through Programming In C Assignment 5 Answers


Question 3
Write a C program to check whether the given number(N) can be expressed as Power of Two (2) or not.
For example 8 can be expressed as 2^3

Solution:

#include < stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
    int temp, flag;
    temp=N;
    flag=0;

    while(temp!=1)
    {
        if(temp%2!=0)
        {
            flag=1;
            break;
        }
        temp=temp/2;
    }

    if(flag==0)
        printf("%d is a number that can be expressed as power of 2.",N);
    else
        printf("%d cannot be expressed as power of 2.",N);
}

These are Problem Solving Through Programming In C Assignment 5 Answers


Question 4
Write a C program to print the following Pyramid pattern upto Nth row. Where N (number of rows to be printed) is taken as input.
For example when the value of N is 5 the pyramid will be printed as follows:
*****
****
***
**
*

Solution:

#include<stdio.h>
int main()
{
    int N;
    scanf("%d", &N);
    int i, j;
    for(i=N; i>0; i--)
    {
        for(j=0;j < i;j++)
        {
  		    printf("*");
        }
  	    printf("\n");
    }
}

These are Problem Solving Through Programming In C Assignment 5 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 5 Answers