ODD 2025, 15B11CI311 – Software Development Fundamentals - I
Course Coordinator: Akanksha Mehndiratta, Dr. Vikas Sharma
JIIT, Sec-128, Noida
ODD 2025
Tutorial Sheet – 5
Software Development Fundamentals – I (15B11CI111)
CO4 Use various C programming constructs to implement iteration, Apply (Level 3)
and recursion
Note: Students are advised to submit their solutions to their respective tutorial
faculties
Q1. Point out the error, if any in the for loop.
#include<stdio.h>
int main()
{
int i=1;
for(; ;)
{
printf("%d\n", i++);
if(i>10)
break;
}
return 0;
}
Q2. Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int a = 10;
switch(a)
{
}
printf("This is c program.");
return 0;
}
Q3. Point out the error, if any in the while loop.
#include<stdio.h>
int main()
{
int i=1;
while()
{
printf("%d\n", i++);
if(i>10)
ODD 2025, 15B11CI311 – Software Development Fundamentals - I
Course Coordinator: Akanksha Mehndiratta, Dr. Vikas Sharma
JIIT, Sec-128, Noida
break;
}
return 0;
}
Q4. The following C program is intended to print all numbers from 1 to 5 using a while loop.
However, it goes into an infinite loop. Find and fix the error(s).
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
printf("%d ", i);
}
return 0;
}
Q5. This program is supposed to read positive integers from the user one by one, and print their
sum. The user will enter -1 to indicate they want to stop entering numbers. However, the program
behaves incorrectly — it either doesn’t stop when -1 is entered or produces the wrong sum. Find
and fix the bugs.
#include <stdio.h>
int main() {
int num = 0;
int sum = 0;
printf("Enter positive numbers to sum, enter -1 to stop:\n");
while (num != -1) {
scanf("%d", &num);
sum += num;
}
printf("Sum is %d\n", sum);
return 0;
}
Q6. Write a C program that uses a do-while loop to repeatedly ask the user to enter a password (a
number between 1000 and 9999). The program should keep asking until the user enters the correct
password: 1234. If the user enters a number outside the valid range, print an error message and ask
again without counting it as an attempt. Once the correct password is entered, print “Access
granted”.
The following code is intended to solve this, but it contains logic errors. Find and fix them.
#include <stdio.h>
ODD 2025, 15B11CI311 – Software Development Fundamentals - I
Course Coordinator: Akanksha Mehndiratta, Dr. Vikas Sharma
JIIT, Sec-128, Noida
int main() {
int password;
do {
printf("Enter your 4-digit password: ");
scanf("%d", &password);
if (password < 1000 && password > 9999) {
printf("Invalid password. Must be 4 digits.\n");
}
} while (password != 1234);
printf("Access granted.\n");
return 0;
}
Q7. The following program is supposed to print a number triangle pattern of n rows. Each row
contains numbers starting from 1 up to the row number. For example, if n = 4, it should print
But the current program contains logic and syntax errors. Identify and fix them.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++);
printf("%d ", j);
printf("\n");
}
return 0;}