0% found this document useful (0 votes)
3 views2 pages

Msword&Rendition 1

The document contains five C programs that perform different tasks: comparing two numbers, finding the smallest among three numbers, checking if a number is even or odd, determining if a number is positive or negative, and checking if a year is a leap year. Each program includes necessary input prompts and conditional statements to achieve its functionality. The code snippets are well-structured and demonstrate basic programming concepts in C.

Uploaded by

f48785237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Msword&Rendition 1

The document contains five C programs that perform different tasks: comparing two numbers, finding the smallest among three numbers, checking if a number is even or odd, determining if a number is positive or negative, and checking if a year is a leap year. Each program includes necessary input prompts and conditional statements to achieve its functionality. The code snippets are well-structured and demonstrate basic programming concepts in C.

Uploaded by

f48785237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1: write a program in C to check a large number between two number.

#include<stdio.h>

int main ()
{
int num1, num2;
num1=12,num2=13;
if (num1 == num2)
printf("both are equal");
else if (num1 > num2)
printf("%d is greater", num1);
else
printf("%d is greater", num2);

return 0;
}

Q2: write a program in c to find the smallest among 3 numbers.

#include <stdio.h>

int main()
{
int a = 5, b = 7, c = 10;

if (a <= b && a <= c)


printf("%d is the smallest",a);

else if (b <= a && b <= c)


printf("%d is the smallest",b);

else
printf("%d is the smallest",c);

return 0;
}

Q3: write a program in c to check whether a number is even or odd.

#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);

// true if num is perfectly divisible by 2


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

return 0;
}

Q4: C Program to Check Whether a Number is Positive or Negative


#include <stdio.h>
int main() {

double num;
printf("Enter a number: ");
scanf("%lf", &num);
if (num <= 0.0) {
if (num == 0.0)
printf("You entered 0.");
else
printf("You entered a negative number.");
}
else
printf("You entered a positive number.");

return 0;
}

Q5: C Program to Check Leap Year.


#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);

// leap year if perfectly divisible by 400


if (year % 400 == 0) {
printf("%d is a leap year.", year);
}
// not a leap year if divisible by 100
// but not divisible by 400
else if (year % 100 == 0) {
printf("%d is not a leap year.", year);
}
// leap year if not divisible by 100
// but divisible by 4
else if (year % 4 == 0) {
printf("%d is a leap year.", year);
}
// all other years are not leap years
else {
printf("%d is not a leap year.", year);
}

return 0;
}

You might also like