14.03.2024 PRB
14.03.2024 PRB
14/03/2024
1) Write a C program to accept two integers and check whether they are
equal or not.
3/15/2024 1
#include <stdio.h> QUESTION 1
int main() {
int a,b;
scanf("%d",&a);
scanf("%d",&b);
// accept two integers from user
if(a==b)//for checking 2 integers whether equal or not
{
printf("%d and %d are equal",a,b);
}
else
{
printf("%d and %d are not equal",a,b);
}
return 0;
}
3/15/2024 2
2. Write a C program to check whether a given number is
even or odd.
3/15/2024 3
#include <stdio.h>
int main()
{
int a; Question 2
scanf("%d",&a);
if(a%2==0)//condition for checking even number
{
printf("%d is a even number",a);
}
else
{
printf("%d is a odd number",a);
}
return 0;
}
3/15/2024 4
3) Write a C program to check whether a
given number is positive or negative.
3/15/2024 5
#include<stdio.h> QUESTION 3
int main()
{
int a;
scanf("%d",&a);
if(a>=0)//condition for positive number
{
printf("%d is a positive number",a);
}
else
{
printf("%d is a negative number",a);
}
return 0;
}
3/15/2024 6
4. Write a C program to find whether a given year is a leap
year or not.
3/15/2024 7
#include <stdio.h> QUESTION 4
int main()
{
int year;
printf ("enter the leap year:");
scanf ("%d", &year);
//condition for checking given year is 4 digit number or not
if(year>=1000 && year<= 9999)
{
//condition for checking leap year
if(year%4==0 || year%400==0)
{
printf("\n%d is a leap year", year);
}
else
{
printf("\n%d is not a leap year", year);
}
}
else
{
printf("\ngiven year is invalid");
}
return
3/15/20240; 8
}
5) Write a C program to read the age of a candidate and determine
whether it is eligible for casting his/her own vote.
3/15/2024 9
#include <stdio.h> QUESTION 5
int main()
{
int age;
printf("enter the age:");
scanf("%d",&age);
if(age>=18)
{
printf("candidate is eligible to vote");
}
else
{
printf("candidate is not eligible to vote");
}
return 0;
}
3/15/2024 10