C Language CONDITION PROGRAM
C Language CONDITION PROGRAM
REALtechSmart
Below is a C program that takes input in seconds and converts it into hours, minutes, and
seconds.
#include <stdio.h>
int main()
{
long int seconds;
int hours, minutes, remaining_seconds;
printf("Enter total seconds: ");
scanf("%ld", &seconds);
if (seconds < 0) // Check for negative input
{
printf("Please Enter a non-negative Value \n");
}
else // Calculate hours
{
hours = seconds / 3600; // 1 hour =3600 seconds
seconds = seconds % 3600; // Calculate remaining sec
minutes = seconds / 60; // Calculate minutes
remaining_seconds = seconds % 60; // remaining sec
printf("Time: %d hours, %d minutes, %d seconds\n",
hours, minutes, remaining_seconds);
}
return 0;
}
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
2|Page
REALtechSmart
Below are a few C language practice programs
demonstrating if, if-else, and nested if-else statements.
Each program includes a brief explanation and is designed
to help you understand the concepts through practical
examples.
1. Simple If Statement
This program checks if a number is positive.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 0) {
printf("%d is positive.\n", num);
}
return 0;
}
Explanation:
The program takes a number as input.
The if statement checks if the number is greater than 0.
If true, it prints that the number is positive.
2. If-Else Statement
This program checks if a number is positive or negative.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 0) {
printf("%d is positive.\n", num);
} else {
printf("%d is negative or zero.\n", num);
}
return 0;
}
Explanation:
The if condition checks if the number is positive.
The else block executes if the condition is false, indicating the number is negative or zero.
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
3|Page
REALtechSmart
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
4|Page
REALtechSmart
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY
5|Page
REALtechSmart
Nested if statements check these conditions step-by-step.
REALtechSmart
ÇgMkSu dh 'kku gj dne vkids lkFk
Trust Of 25 Years
Contact :9314397377 HINDAUN CITY