Problem Solving Through Programming in C Week 8: Programming Assignments Jan-Jun 2022

    NPTEL PROGRAMMING ASSIGNMENTS


Problem Solving Through Programming in C

Week-08 Program-01

Due Date of Submission 2022-03-24, 23:59 IST
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);
}


 

 




Week-08 Program-02

Due Date of Submission 2022-03-24, 23:59 IST
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.


#include <stdio.h>  
long power(int, int);
int main()
{
int pow, num;
long result;
scanf("%d", &num); //The number taken as input from test case data 
scanf("%d", &pow); //The power is taken from the test case 
result = power(num, pow);
printf("%d^%d is %ld", num, pow, result);
return 0;
}


 

 




Week-08 Program-03

Due Date of Submission 2022-03-24, 23:59 IST
Write a C Program to print Binary Equivalent of an Integer using Recursion.


#include <stdio.h>
int binary_conversion(int); //function to convert binary to decimal number
int main()
  {
  int num, bin;  //num is the decimal number and bin is the binary equivalent for the number
  scanf("%d", &num); //The decimal number is taken from the test case data
  bin = binary_conversion(num); //binary number is stored in variable bin
  printf("The binary equivalent of %d is %d\n", num, bin);
  return 0;
  }

 

 





Week-08 Program-04

Due Date of Submission 2022-03-24, 23:59 IST
Write a C program to print a triangle of prime numbers upto given number of lines of the triangle. e.g If number of lines is 3 the triangle will be
2
3 5
7 11 13



#include<stdio.h>
int prime(int num); //Function to find whether the number is prime or not.
int main() {
   int lines;
   scanf("%d", &lines);

 

 


Post a Comment (0)
Previous Post Next Post