# NPTEL Problem Solving Through Programming In C WEEK 8 Assignment July 2022

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

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 HCF of 4 given numbers using recursive function

```				```
#include<stdio.h>
int HCF(int, int); //You have to write this function which calculates the HCF.

int main()
{
int a, b, c, d, result;
scanf("%d %d %d %d", &a, &b, &c, &d); /* Takes 4 number as input from the test data */
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;
}

```
```

#### Course Name : “Problem Solving through Programming In C 2022”

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

```				```
#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);
}

```
```

#### Course Name : “Problem Solving through Programming In C 2022”

Question : 3  Write a program to calculate the sum of a given series.

```				```
#include <math.h> //For using the pow() to calculate power
#include <stdio.h>
double Series_Sum(int n); /* function for calculation the series sum */
int main()
{
int n;
scanf("%d", &n);
double Result;
Result = Series_Sum(n);

printf("The sum of the series is = %.6f\n", Result);
return 0;
}

double Series_Sum(int n)
{
int i;
double sums = 0.0, ser;
for(i = 1; i <= n; ++i)
{
ser = 1 / pow(i, i);
sums += ser;
}
return sums;
}
```
```

#### Course Name : “Problem Solving through Programming In C 2022”

Question : 4  Write a program to express a given integer as a Sum of Two Prime Numbers
For example if the number is 10
The result will be
10 = 3 + 7
10 = 5 + 5

```				```
#include <stdio.h>
int checkPrime(int n);
int main()
{
int n;
scanf("%d", &n);

int  i,flag = 0;
for(i = 2; i <= n / 2; ++i)
{
if(checkPrime(i) == 1)
{
if(checkPrime(n - i) == 1)
{
printf("%d = %d + %d\n", n, i, n - i);
flag = 1;
}
}
}

if(flag == 0)
printf("%d cannot be expressed as the sum of two prime numbers.", n);

return 0;
}

// function to check prime number
int checkPrime(int n){
int i, isPrime = 1;

if (n == 0 || n == 1) {
isPrime = 0;
}
else {
for(i = 2; i <= n/2; ++i) {
if(n % i == 0) {
isPrime = 0;
break;
}
}
}
return isPrime;
}
```
```