NPTEL Problem Solving Through Programming In C - Programming Assignment Week-8 Sept-2023 Swayam

 

Week 8 : Programming Assignment 1

Due on 2023-09-21, 23:59 IST
Write a C Program to find HCF of 4 given numbers using recursive function
Select the Language for this assignment. 
#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);
}
 
//Complete the rest of the program to calculate HCF
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;
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
100
30
50
70
The HCF is 10
The HCF is 10
Passed
Test Case 2
49
56
147
21
The HCF is 7
The HCF is 7
Passed



Week 8 : Programming Assignment 2

Due on 2023-09-21, 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
Select the Language for this assignment. 
#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;
}
long power(int num, int pow)
{
if (pow)
{
return (num * power(num, pow - 1));
}
return 1;
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
5
2
5^2 is 25
5^2 is 25
Passed
Test Case 2
10
4
10^4 is 10000
10^4 is 10000
Passed



Week 8 : Programming Assignment 3

Due on 2023-09-21, 23:59 IST
Write a C Program to print Binary Equivalent of an Integer using Recursion
Select the Language for this assignment. 
#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;
  }
int binary_conversion(int num)
  { 
     if (num == 0)
        {
            return 0;
        }
        else
        {
            return (num % 2) + 10 * binary_conversion(num / 2);
        }
  }
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
10
The binary equivalent of 10 is 1010
The binary equivalent of 10 is 1010\n
Passed after ignoring Presentation Error
Test Case 2
257
The binary equivalent of 257 is 100000001
The binary equivalent of 257 is 100000001\n
Passed after ignoring Presentation Error



Week 8 : Programming Assignment 4

Due on 2023-09-21, 23:59 IST
Write a C Program to reverse a given word using function. e.g. INDIA should be printed as AIDNI
Your last recorded submission was on 2023-09-10, 22:21 IST
Select the Language for this assignment. 
#include<stdio.h>
#include<string.h>
 
void reverse(char[], int, int);
    int main()
    {
        char str1[20];
        scanf("%s", str1); //The string is taken as input form the test data. 
     
/* Complete the program to print the string in reverse order using the function
void reverse(char[], int, int);
Use the printf statement as
printf("The string after reversing is: %s\n", str1); 
You can use different variable also.
*/
        reverse(str1, strlen(str1), 0);
        printf("The string after reversing is: %s", str1);
        return 0;
}
 
void reverse(char str1[], int len, int i)
{
  char temp;
  for(int i=0; i<len/2; i++)
  {
    temp = str1[i];
    str1[i] = str1[len-i-1];
    str1[len-i-1] = temp;
  }
  str1[len]='\0';
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
computer
The string after reversing is: retupmoc
The string after reversing is: retupmoc
Passed
Test Case 2
NPTEL
The string after reversing is: LETPN
The string after reversing is: LETPN
Passed



No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...