NPTEL Problem Solving Through Programming In C WEEK 4 Assignment 2022

Problem-solving-through-Programming-In-C-Week4-Programming-Assignment-Solutions

NPTEL Problem solving through Programming In C Week 4 All Programming Assignment Solutions | Swayam 2022. With the growth of Information and Communication Technology, there is a need to develop large and complex software.

ABOUT THE COURSE:

This course is aimed at enabling the students to:
  • Formulate simple algorithms for arithmetic and logical problems
  • Translate the algorithms to programs (in C language)
  • Test and execute the programs and  correct syntax and logical errors
  • Implement conditional branching, iteration and recursion
  • Decompose a problem into functions and synthesize a complete program using divide and conquer approach
  • Use arrays, pointers and structures to formulate algorithms and programs
  • Apply programming to solve matrix addition and multiplication problems and searching and sorting problems 
  • Apply programming to solve simple numerical method problems, namely rot finding of function, differentiation of function and simple integration
COURSE LAYOUT
    • Week 1 : Introduction to Problem Solving through programs, Flowcharts/Pseudo codes, the compilation process, Syntax and Semantic errors, Variables and Data Types
    • Week 2 : Arithmetic expressions, Relational Operations, Logical expressions; Introduction to Conditional Branching
    • Week 3 : Conditional Branching and Iterative Loops
    • Week 4 : Arranging things : Arrays
    • Week 5 : 2-D arrays, Character Arrays and Strings 
    • Week 6 : Basic Algorithms including Numerical Algorithms
    • Week 7 : Functions and Parameter Passing by Value
    • Week 8 : Passing Arrays to Functions, Call by Reference
    • Week 9 : Recursion
    • Week 10 : Structures and Pointers
    • Week 11 : Self-Referential Structures and Introduction to Lists
    • Week 12 : Advanced Topics

Once again, thanks for your interest in our online courses and certification. Happy learning!

Course Name : “Problem Solving through Programming In C 2022

Question : 1  Write a C Program to Find the Smallest Number among Three Numbers (integer values) using Nested IF-Else statement.

				
					#include <stdio.h>
int main()
{
    int n1, n2, n3; 
    scanf("%d %d %d", &n1, &n2, &n3);
    if(n1<n2)
    {
        if(n1<n3)
            printf("%d is the smallest number.", n1);
        else
            printf("%d is the smallest number.", n3);
    }
    else
    {
        if(n2<n3)
            printf("%d is the smallest number.", n2);
        else
            printf("%d is the smallest number.", n3);
    }
}
				
			

Course Name : “Problem Solving through Programming In C

Question : 2  Write a program to find whether a given character is a Vowel or consonant. A character is taken as input. The character may be in Upper Case or in Lower Case.

				
					#include <stdio.h>
int main()
{
    char ch;
    scanf("%c",&ch);
    int lowercase_vowel, uppercase_vowel;

	// evaluates to 1 if variable c is a lowercase vowel
    lowercase_vowel = (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');

    // evaluates to 1 if variable c is a uppercase vowel
    uppercase_vowel = (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U');

    // evaluates to 1 (true) if c is a vowel
    if (lowercase_vowel || uppercase_vowel)
        printf("%c is a vowel.", ch);
    else
        printf("%c is a consonant.", ch);
    return 0;
}
				
			

Course Name : “Problem Solving through Programming In C

Question : 3  Write a C program to calculate the Sum of First and the Last Digit of a given Number.
For example if the number is 1234 the result is 1+ 4 = 5.

				
					#include <stdio.h>
int main()
{

    int N, First_digit, Last_digit;
    scanf("%d", &N);
    
    Last_digit = N%10;
    First_digit = N;

    while(First_digit >=10)
    {
        First_digit = First_digit/10;
    }
    printf("Sum of First and Last digit = %d", First_digit + Last_digit);
    return 0;
}

				
			

Course Name : “Problem Solving through Programming In C

Question : 4 Write a C program to find power of a number using while loops. The base number (>0) and exponent (>=0) is taken from the test cases.

				
					#include <stdio.h>
int main()
{
    int base, exponent;
    long int result;
    scanf("%d", &base); 
    scanf("%d", &exponent); 
    if(exponent == 0) 
        result = 1;
    else
    {
        result = 1;
        while(exponent != 0)
        {
          result = result * base;
          --exponent;
      	}
    }
    printf("The result is : %ld\n", result);
    return 0;
}