
☞ Introduction to Programming in C
NPTEL- Week 5: Assignment 5 Answers- 2025
#include<stdio.h>
void reverse()
{
char c = getchar();
if (c == EOF)
{
return;
}
reverse();
putchar(c);
}
int main()
{
reverse();
return 0;
}
#include<stdio.h>
void genBinary(char s[], int i, int n)
{
if (i == n)
{
s[n] = '\0';
puts(s);
return;
}
s[i] = '0';
genBinary(s, i + 1, n);
s[i] = '1';
genBinary(s, i + 1, n);
}
int main()
{
int n;
char s[10];
scanf("%d", &n);
genBinary(s, 0, n);
return 0;
}
The following is the recursive definition of BlockSum: If size of M is 2, say M = [a, b], where a and b are integers, then
BlockSum(M ) = a − b.
Otherwise (when n > 2), partition M into two subarrays of equal size:
M = [A B C D]
The BlockSum of M is defined recursively as :
BlockSum(M) = BlockSum(A) − BlockSum(B).
#include<stdio.h>
int BlockSum(int *M, int n)
{
if (n == 2)
{
return M[0] - M[1];
}
else
{
int half = n / 2;
int sumA = BlockSum(M, half);
int sumB = BlockSum(M + half, half);
return sumA - sumB;
}
}
int main()
{
int n, a[20];
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
int result = BlockSum(a, n);
printf("%d", result);
return 0;
}
☞ NPTEL - Introduction to Programming in C - Week 7:Assignment 7 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 6:Assignment 6 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 5:Assignment 5 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 4:Assignment 4 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 3:Assignment 3 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 2:Assignment 2 Answers- 2025
☞ NPTEL - Introduction to Programming in C - Week 1:Assignment 1 Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 12:Assignment 12 Answers- 2025
☞ NPTEL - Programming in Java - Week 12 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 11:Assignment 11 Answers- 2025
☞ NPTEL - Programming in Java - Week 11 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 10:Assignment 10 Answers- 2025
☞ NPTEL - Programming in Java - Week 10 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 9:Assignment 9 Answers- 2025
☞ NPTEL - Programming in Java - Week 09 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 8:Assignment 8 Answers- 2025
☞ NPTEL - Programming in Java - Week 08 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 7:Assignment 7 Answers- 2025
☞ NPTEL - Programming in Java - Week 07 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 6:Assignment 6 Answers- 2025
☞ NPTEL - Programming in Java - Week 06 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 5:Assignment 5 Answers- 2025
☞ NPTEL - Programming in Java - Week 05 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 4:Assignment 4 Answers- 2025
☞ NPTEL - Programming in Java - Week 04 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 3:Assignment 3 Answers- 2025
☞ NPTEL - Programming in Java - Week 03 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 2:Assignment 2 Answers- 2025
☞ NPTEL - Programming in Java - Week 02 : Programming Assignments Answers- 2025
☞ NPTEL - Programming in Java - QUIZ : Week 1:Assignment 1 Answers- 2025
☞ NPTEL - Programming in Java - Week 01 : Programming Assignments Answers- 2025