Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Programming

Fundamentals
Assignment-4

2K22/A11/16
Q1) Write a program in C, take student age as an input. If his age is
greater than or equal to 18 then show the message “You are eligible for
voting” otherwise show the message “You are not eligible for voting”.
Input :
#include <stdio.h>

int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18) {
printf("You are eligible for voting\n");
}
else {
printf("You are not eligible for voting\n");
}
return 0;
}

Output :
Q 2. Write a program in C to check entered number is even or odd.
Input :
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("%d is even.\n", num);
} else {
printf("%d is odd.\n", num);
}
return 0;
}

Output :
Q3. Write a program to check whether the input character is a vowel or
consonant.
Input :

#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch ==
'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
printf("%c is a vowel.", ch);
}
else {
printf("%c is a consonant.", ch);
}
return 0;
}

Output :
Q4. Write a program to find out if the year entered is a leap year or not.
Input :

#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
printf("%d is a leap year.", year);
}
else {
printf("%d is not a leap year.", year);
}
return 0;
}

Output :

You might also like