Day 3 of Programming in C
Write a program to check whether the given year is leap year or not.
#include <stdio.h>
void main(){
int year;
printf("Enter a year: ");
scanf("%d", &year);
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
printf("It is a leap year\n");
} else {
printf("It is not a leap year\n");
}
}
Step 1: Declare an integer variable `year`.
Step 2: Take user input for the year.
Step 3: Check leap year conditions:
• Year is divisible by 400 OR
• Year is divisible by 4 AND not divisible by 100
Step 4: Print whether it's a leap year or not based on the condition.
Step 2: Take user input for the year.
Step 3: Check leap year conditions:
• Year is divisible by 400 OR
• Year is divisible by 4 AND not divisible by 100
Step 4: Print whether it's a leap year or not based on the condition.
Take 5 numbers from keyboard.Find the mean of those number.Display the 5 numbers in such a way that the number which is less than equal to mean will be represented by 0 otherwise 255.
#include <stdio.h>
void main(){
float a,b,c,d,e,mean;
printf("Enter 5 numbers : ");
scanf("%f%f%f%f%f",&a,&b,&c,&d,&e);
mean = (a+b+c+d+e)/5;
printf("Output:\na = %d\nb = %d\nc = %d\nd = %d\ne = %d\n",
(a <= mean) ? 0 : 255,
(b <= mean) ? 0 : 255,
(c <= mean) ? 0 : 255,
(d <= mean) ? 0 : 255,
(e <= mean) ? 0 : 255);}
Step 1: Declare float variables `a, b, c, d, e` and `mean`.
Step 2: Take user input for 5 numbers.
Step 3: Calculate mean by summing all numbers and dividing by 5.
Step 4: Use ternary operators to print:
• 0 if number ≤ mean
• 255 if number > mean
Step 5: Display transformed values for all numbers.
Step 2: Take user input for 5 numbers.
Step 3: Calculate mean by summing all numbers and dividing by 5.
Step 4: Use ternary operators to print:
• 0 if number ≤ mean
• 255 if number > mean
Step 5: Display transformed values for all numbers.
Comments