Professional Documents
Culture Documents
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;
}
2
Q2) Accept a character as input and check whether the character is a
digit.(Check if it is in the range ‘0’ to ‘9’ both inclusive)
#include<stdio.h>
#include<ctype.h>
int main()
{
char TestChar;
printf("\n Check whether a character is digit or not :\n");
printf("----------------------------------------------\n");
printf(" Input a character : ");
scanf( "%c", &TestChar );
if( isdigit(TestChar) )
printf( " The entered character is a digit. \n\n" );
else
printf( " The entered character is not a digit. \n\n" );
return 0;
}
3
Q3) Write a program, which accepts annual basic salary of an employee and calculates and displays
the Income tax as per the following rules.
Basic: < 1,50,000 Tax = 0 %
1,50,000 to 3,00,000 Tax = 20% >
3,00,000 Tax = 30%
#include <stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float salary,tax;
printf("enter the emp basic salary :");
scanf("%f",&salary);
if(salary<=150000)
{
tax=0;
printf("tax = %f",tax);
}
else if(salary>150000 && salary<=300000)
{
tax=(salary*0.2);
printf("tax = %f",tax);
}
else if(salary>300000)
{
4
tax=(salary*0.3);
printf("tax = %f",tax);
}
}
Q4) Accept a character from the user and check whether the character is a
vowel or consonant . (Hint: a,e,i,o,u,A,E,I,O,U are vowels)
#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
5
else
printf("%c is a consonant.", c);
return 0;
}
OUTPUT 1 :
OUTPUT 2:
Q5) Accept any year as input through the keyboard . Write a Program to
check whether the year is a leap year or not. ( Hint : leap year is divisible
by 4 and not by 100 or divisible by 400)
#include <stdio.h>
int main() {
6
int year;
printf("Enter a year: ");
scanf("%d", &year);
return 0;
}
7
OUTPUT 1 :
OUTPUT 2:
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if(ch >= 'A' && ch <= 'Z')
{
8
printf("'%c' is uppercase alphabet.", ch);
}
else if(ch >= 'a' && ch <= 'z')
{
printf("'%c' is lowercase alphabet.", ch);
}
else if(ch>=0 && ch<=9)
{
printf("'%c' is not an alphabet.", ch);
}
}
9
Q7) Accept the x and y coordinate of a point and find the quadrant in
which the point lies.
#include <stdio.h>
void main()
{
int co1,co2;
10
Q8) Accept the Cost price and selling price from the keyboard .Find out if
the seller has made the profit or loss and display how much profit or loss
has been made.
#include<stdio.h>
int main()
{
float cost,price,m;
printf("enter cost of keyboard : ");
scanf("%f",&cost);
printf("\n enter selling price of keyboard : ");
scanf("%f",&price);
m=cost - price;
if(m>0)
{
printf("loss = %f",m);
}
11
else if(m<0)
{
m=(-1)*m;
printf("profit = %f",m);
}
else
{
printf("NO profit NO loss");
}
}
OUTPUT:
12
13