0% found this document useful (0 votes)
15 views4 pages

Day 3

The document contains four C programming examples: one to check if a number is even or odd, another to find the largest of three numbers using nested if-else statements, a third to determine grades based on marks using a switch-case structure, and a fourth to print numbers from 1 to 10 while skipping those divisible by 3. Each program includes user input and appropriate control flow mechanisms. These examples serve as basic exercises for understanding conditional statements and loops in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Day 3

The document contains four C programming examples: one to check if a number is even or odd, another to find the largest of three numbers using nested if-else statements, a third to determine grades based on marks using a switch-case structure, and a fourth to print numbers from 1 to 10 while skipping those divisible by 3. Each program includes user input and appropriate control flow mechanisms. These examples serve as basic exercises for understanding conditional statements and loops in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DAY 3

1. Program to Check if a Number is Even or Odd


#include <stdio.h>

int main() {
int num;

printf("Enter an integer: ");


scanf("%d", &num);

if (num % 2 == 0) {
printf("%d is even.\n", num);
} else {
printf("%d is odd.\n", num);
}

return 0;
}
2. Program to Find the Largest of Three Numbers Using Nested If-Else
#include <stdio.h>

int main() {
int a, b, c;

printf("Enter three integers:\n");


scanf("%d %d %d", &a, &b, &c);

if (a > b) {
if (a > c) {
printf("%d is the largest number.\n", a);
} else {
printf("%d is the largest number.\n", c);
}
} else {
if (b > c) {
printf("%d is the largest number.\n", b);
} else {
printf("%d is the largest number.\n", c);
}
}

return 0;
}
3. Program to Check the Grade Based on Marks Using Switch-Case

#include <stdio.h>

int main() {
int marks;

printf("Enter the marks (0-100): ");


scanf("%d", &marks);

// Ensure marks are within valid range


if (marks < 0 || marks > 100) {
printf("Invalid marks.\n");
return 1;
}
switch (marks / 10) {
case 10:
case 9:
printf("Grade A\n");
break;
case 8:
printf("Grade B\n");
break;
case 7:
printf("Grade C\n");
break;
case 6:
printf("Grade D\n");
break;
case 5:
printf("Grade E\n");
break;
default:
printf("Grade F\n");
break;
}

return 0;
}
4. Program to Print Numbers from 1 to 10 but Skip Numbers Divisible by 3
(Using Break and Continue)
#include <stdio.h>

int main() {
for (int i = 1; i <= 10; i++) {
if (i % 3 == 0) {
continue; // Skip the rest of the loop body if number is divisible by 3
}
printf("%d\n", i);
}

return 0;
}

You might also like