C Programming Manual Lab 4 To 6
C Programming Manual Lab 4 To 6
NAME: _________________________________________________________
LEVEL: _________________________________________________________
FACULTY: ______________________________________________________
DEPARTMENT: ________________________________________________
PROGRAMME: _________________________________________________
MATRIC NUMBER: ____________________________________________
Lab 4: Control Statements (Conditional): If and Its Variants, Switch
(Break)
Objectives:
Tasks:
1. If Statement:
#include <stdio.h>
int main()
if (num > 5)
return 0;
}
2. If-Else Statement:
int main()
int num = 3;
if (num > 5) {
else
return 0;
}
3. Nested If Statements:
#include <stdio.h>
int main()
int x = 10, y = 5;
if (x > y) {
if (x == 10) {
return 0;
}
4. Switch Statement:
#include <stdio.h>
int main()
int choice = 2;
switch (choice) {
case 1:
printf("Choice 1 selected\n");
break;
case 2:
printf("Choice 2 selected\n");
break;
default:
printf("Invalid choice\n");
return 0;
5. If-Else If Ladder:
Objective: Learn to use the "if-else if" ladder for handling multiple
conditions.
Task: Extend the previous program to include an "else if" ladder to handle
additional cases.
#include <stdio.h>
int main()
printf("Grade: A\n");
printf("Grade: B\n");
printf("Grade: C\n");
} else {
printf("Grade: F\n");
return 0;
}
#include <stdio.h>
int main()
int num = 7;
return 0;
}
7. Switch Statement with Fallthrough:
#include <stdio.h>
int main()
int day = 2;
switch (day) {
case 1:
printf("Monday\n");
case 2:
printf("Tuesday\n");
break;
default:
printf("Invalid day\n");
return 0;
Assignment
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
Lab 5: Goto Statement, Control Statements (Looping): While, Do..While,
For Loop, Continue & Break (Unconditional), Nested Loops
Objectives:
Understand the usage of "continue" and "break" statements for loop control.
Theory: The "goto" statement allows unconditional jumps within a program, while
looping constructs such as "while," "do..while," and "for" provide structured ways
to repeat a block of code. Additionally, "continue" and "break" statements enhance
control within loops, and nested loops involve the use of loops within loops.
Tasks:
1. Goto Statement:
#include <stdio.h>
int main()
int count = 0;
start:
count++;
if (count < 5) {
goto start;
return 0;
}
2. While Loop:
#include <stdio.h>
int main()
int i = 1;
while (i <= 5) {
i++;
printf("\n");
return 0;
3. Do..While Loop:
#include <stdio.h>
int main() {
do {
scanf("%d", &num);
sum += num;
} while (num != 0);
return 0;
4. For Loop:
#include <stdio.h>
int main()
int num, i;
scanf("%d", &num);
return 0;
}
5. Continue Statement:
int main() {
int i;
if (i % 2 == 0) {
printf("\n");
return 0;
6. Break Statement:
#include <stdio.h>
int main() {
int i;
if (i == 5) {
printf("\n");
return 0;
}
Nested Loops:
#include <stdio.h>
int main() {
int i, j;
printf("* ");
printf("\n");
return 0;
Assignment
1. Write a program that accepts a number as input, checks and ensure that
the number is greater than 10, and then goes ahead to calculate the sum
of its digits.
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
2. Write a program that accepts a number as input, then generates the
multiplication table for the number up to 12.
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
Lab 6: Arrays, One-Dimensional Array: Declaration and Initialization
Objectives:
Theory: Arrays allow you to store multiple values of the same data type under a
single name. This lab focuses on the basics of arrays, specifically the declaration
and initialization of one-dimensional arrays.
Tasks:
1. Array Declaration:
#include <stdio.h>
int main()
// Array Declaration
int numbers[5];
return 0;
} 2. Array Initialization:
Objective: Learn different methods for initializing an array.
int main() {
// Array Initialization
return 0;
#include <stdio.h>
int main() {
return 0;
}
4. Array Size and Iteration:
#include <stdio.h>
int main()
int sum = 0;
sum += numbers[i];
return 0;
arr[i] *= 2;
int main() {
modifyArray(numbers, size);
return 0;
Assignment
1. Write a program that accepts seven scores into an array, then displays the
minimum score as well as the maximum score in the array.
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
2. Write a program that identifies and removes duplicate skills from an array
named “programming_skills”.
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________
___________________________________________________________