NPTEL 3 min read

Problem Solving Through Programming In C Week8 Assignment July 2023

Faheem Ahmad

0 reads

Problem-Solving-Through-Programming-In-C-Week8-Assignment-July-2023

NPTEL Problem Solving Through Programming In C Week8 All Programming Assignment Solutions | Swayam July 2023. 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!

Problem Solving through Programming In C July 2023

Question : 1 Write a C Program to find HCF of 4 given numbers using recursive function.

C
#include<stdio.h>
int HCF(int, int);
	 
int main()
{
   int a, b, c, d, result;
   scanf("%d %d %d %d", &a, &b, &c, &d);
   result = HCF(HCF(a, b), HCF(c,d));
   printf("The HCF is %d", result);
}

int HCF(int x, int y)
{
   while (x != y)
   {
      if (x > y)
      {
           return HCF(x - y, y);
      }
      else
      {
       	   return HCF(x, y - x);
      }
   }
   return x;
}

Problem Solving through Programming In C July 2023

Question : 2  Write a C Program to find power of a given number using recursion. The number and the power to be calculated is taken from test case.

C
#include <stdio.h>  
long power(int, int);
int main()
{
    int pow, num;
    long result;
    scanf("%d", &num); 
    scanf("%d", &pow);
    result = power(num, pow);
    printf("%d^%d is %ld", num, pow, result);
    return 0;
}

long power(int num, int pow)
{
  if(pow)
  {
  	return (num * power(num, pow - 1));
  }
  return 1;
}

Problem Solving through Programming In C July 2023

Question : 3  Write a C Program to print Binary Equivalent of an Integer using Recursion.

C
#include <stdio.h>
int binary_conversion(int);
int main()
{
  int num, bin;
  scanf("%d", &num);
  bin = binary_conversion(num);
  printf("The binary equivalent of %d is %d\n", num, bin);
  return 0;
}

int binary_conversion(int num)
{ 
     if(num == 0)
     {
     	return 0;
     }
     else
     {
     	return (num%2) + 10 * binary_conversion(num/2);
     }
}

Problem Solving through Programming In C July 2023

Question : 4 Write a C Program to reverse a given word using function. e.g. INDIA should be printed as AIDNI

C
#include<stdio.h>
#include<string.h>

void reverse(char[], int, int);
int main()
{
    char str1[20];
    scanf("%s", str1);
    int length = strlen(str1);
    reverse(str1, 0, length - 1);
    printf("The string after reversing is: %s", str1); 
    return 0;
}

void reverse(char str[], int start, int end) {
    while (start < end) {
        char temp = str[start];
        str[start] = str[end];
        str[end] = temp;
        start++;
        end--;
    }
}

// written by

Faheem Ahmad

Writer at Techies Talk

Faheem writes about NPTEL, Coursera, and How To on Techies Talk, turning tricky topics into guides you can follow step by step.

Writes about #NPTEL117 #Coursera13 #How To5

Articles
144
Reads
173
Writing since
2020
All posts by Faheem