C PROGRAMMING • WEEK 3
NPTEL - Introduction to Programming in C - Week 3:Assignment 3 Answers- 2025
NPTEL • Introduction to Programming in C
Week 3 : Assignments - NPTEL >> Introduction to Programming In C - 2025
Week 3 : Assignment 3 - Question 1
Write a program that reads N integers one by one and prints the largest among them.
Solution :
#include<stdio.h>
int main()
{
char c,shift;
scanf("%c",&c);
shift = c + 3;
if(shift > 'z')
{
shift = shift-'z' + 'a' -1;
}
printf("%c",shift);
return 0;
}
Week 3 : Assignment 3 - Question 2
Complete the function int is prime(int n) to check if a positive number n is prime or not.
Solution :
#include<stdio.h>
// Complete this function to check if a number is prime
// Return 1 if n is prime 0 if not
int is_prime(int n) {
if (n <= 1) {
return 0;
}
for(int i=2;i<=n/2;i++)
{
if(n%i==0)
return(0);
}
return(1);
}
int main() {
int n, num;
scanf("%d", &n);
int flag = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &num);
if (is_prime(num)) {
if(flag == 0){
printf("%d", num);
flag = 1;
}
else{
printf(" %d", num);
}
}
}
return 0;
}
Week 3 : Assignment 3 - Question 3
Write a C program that takes a single lowercase English letter as input and shifts it three positions forward in the alphabet using the Caesar cipher technique.
Solution :
#include<stdio.h>
int main()
{
char c,shift;
scanf("%c",&c);
shift = c + 3;
if(shift > 'z')
{
shift = shift-'z' + 'a' -1;
}
printf("%c",shift);
return 0;
}