Lab3 2023103623
Lab3 2023103623
void main()
{
int age;
printf("What is your age? \n");
scanf("%d",&age);
if(age<18)
printf("\n The Person is not eligible to vote");
else if(age>18)
printf("\n The Person is eligible to vote");
else
printf("\n The Person is imaginary ");
}
2. Write a C program to check whether a number is odd or even.
CODE:-
//Program to check whether a number is even or odd
#include<stdio.h>
void main()
{
int number;
printf("Enter a number: \n");
scanf("%d",&number);
if(number%2==0)
printf("\n THE NUMBER IS EVEN");
else if(number%2!=0)
printf("\n THE NUMBER IS ODD");
else
printf("\n THE ENTERED CHARACTER IS NOT A NUMBER");
}
3. Write a C program to check whether a number is positive, negative or zero.
CODE:-
//Program to check whether a number is postive negative or zero
#include<stdio.h>
void main()
{
int number;
printf("Enter a number: \n");
scanf("%d",&number);
if(number<0)
printf("\n THE NUMBER IS NEGATIVE");
else if(number>0)
printf("\n THE NUMBER IS POSITIVE");
else
printf("\n THE NUMBER IS 0");
}
4. Write a C program to check whether two numbers are equal, greater or less than each other.
CODE:-
//Program to check whether two numbers are equal,greater or less than each other
#include<stdio.h>
void main()
{
int n1,n2;
printf("Enter number 1: \n");
scanf("%d",&n1);
printf("Enter number 2: \n");
scanf("%d",&n2);
if(n1==n2)
printf("\n THE NUMBERS ARE EQUAL");
else if(n1>n2)
printf("\n THE NUMBER 1 IS GREATER THAN 2");
else
printf("\n THE NUMBER 2 IS GREATER THAN 1");
}
5. Write a C program to check whether the character entered by the user is uppercase or lowercase.
CODE:-
//Program to check whether the character entered is uppercase or lowercase
#include<stdio.h>
#include<ctype.h>
void main()
{
char ch;
printf("Enter a character: \n");
scanf("%c",&ch);
if(islower(ch)!=0)
printf("THE ENTERED CHARACTER IS IN LOWERCASE \n");
else if(isupper(ch)!=0)
printf("THE ENTERED CHARACTER IS IN UPPERCASE \n");
}
6. Write a C program to read an angle from the user and display the quadrant.
CODE:-
//Program to read an angle from the user and display the quadrant
#include<stdio.h>
#include<ctype.h>
void main()
{
double a;
printf("Enter an angle: \n");
scanf("%lf",&a);
if(a<=90 && a>=0)
printf("THE ANGLE IS IN 1ST QUADRANT \n");
else
printf("THE ANGLE IS IN 4TH QUADRANT \n");
}
7. Write a C program to check whether the given year is leap year or not. [Hint: A year is said to be
leap if it is divisible by 4 and either by 400 or not by 100]
CODE:-
//Program to check whether the given year is leap year or not.
#include<stdio.h>
void main()
{
int year;
printf("Enter a year: \n");
scanf("%d",&year);
if(year%400==0)
printf("\n THE YEAR IS A LEAP YEAR");
else if(year%100==0)
printf("\n THE YEAR IS NOT A LEAP YEAR");
else if(year%4==0)
printf("\n THE YEAR IS A LEAP YEAR");
else
printf("\n THE YEAR IS NOT A LEAP YEAR");
}
8. Write a C program to find the biggest of three numbers.
CODE:-
//Program to find the biggest of three numbers.
#include<stdio.h>
void main()
{
int a,b,c,max;
printf("Enter value for a: \n");
scanf("%d",&a);
printf("Enter value for b: \n");
scanf("%d",&b);
printf("Enter value for c: \n");
scanf("%d",&c);
max=a;
if(max<b)
max=b;
if(max<c)
max=c;
printf("The biggest of the three numbers is %d",max);
}
9. Write a C program to calculate the roots of the quadratic equation.
CODE:-
//Program to calculate the roots of the quadratic equation.
#include<stdio.h>
#include<math.h>
void main()
double a,b,c;
scanf("%lf",&a);
scanf("%lf",&b);
scanf("%lf",&c);
d = b*b - 4*a*c;
if(d>0)
{
r1= (-b + sqrt(d))/(2*a);
else if(d==0)
r1= sqrt(d)/(2*a);
else
real = -b / (2 * a);
}
SPOT QUESTION:
10. Write a C program to determine the character entered by the user. [Hint: Use functions like
isalpha(), isdigit(), islower(), isupper(), ispunct(), isspace() defined in ctype.h]
CODE:-
//on spot question
#include<stdio.h>
#include<ctype.h>
void main()
{
char ch;
printf("ENTER ANY CHARACTER");
scanf("%c",&ch);
if(isalpha(ch)!=0)
{
printf("THE ENTERED CHARACTER IS AN ALPHABET \n");
if(islower(ch)!=0)
printf("THE ENTERED CHARACTER IS IN LOWERCASE \n");
else if(isupper(ch)!=0)
printf("THE ENTERED CHARACTER IS IN UPPERCASE \n");
}
else if(isdigit(ch)!=0)
printf("THE ENTERED CHARACTER IS A DIGIT \n");
else if(ispunct(ch)!=0)
printf("THE ENTERED CHARACTER IS A PUNCTUATION \n");
else if(isspace(ch)!=0)
printf("THE ENTERED CHARACTER IS A SPACE \n");
else
printf("INVALID CHARACTER IS ENTERED \n");
}