Practical 3
Practical 3
Code:
#include <stdio.h>
int main()
int num;
scanf("%d", &num);
if(num % 2 == 0)
else
return 0;
P2: Write a program to accept three numbers and check whether the first is between the other
two numbers. Ex: Input 20 10 30. Output: 20 is between 10 and 3
Code:
#include<stdio.h>
int main()
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
else
#include<stdio.h
int main()
int a;
else
return 0;
P4: Write a program, which accepts annual basic salary of an employee and calculates and
displays
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
float salary,tax;
scanf("%f",&salary);
if(salary<=150000)
tax=0;
printf("tax = %f",tax);
tax=(salary*0.2);
printf("tax = %f",tax);
}
else if(salary>300000)
tax=(salary*0.3);
printf("tax = %f",tax);
P5: Accept a character from the user and check whether the character is a vowel or consonant.
#include <stdio.h>
int main()
char c;
scanf("%c", &c);
if (lowercase_vowel || uppercase_vowel)
else
return 0;
}
and Lowercase characters have ASCII values in the range of 97 to122, uppercase is
#include <stdio.h>
int main()
char ch;
scanf("%c", &ch);
else
{
printf("The character is not a Digit or a Letter.\n");
return 0;
P7: Accept a character as input and check whether the character is a digit.
#include <stdio.h>
int main()
char ch;
scanf("%c", &ch);
else
return 0;
P8: Write a program to accept marks for three subjects. Calculate the average and also display
the class obtained. (Distinction – above Class I – above %, class II –
#include <stdio.h>
int main() {
float average;
scanf("%f", &marks1);
scanf("%f", &marks2);
scanf("%f", &marks3);
// Calculate average
printf("Class: Distinction\n");
else
printf("Class: Fail\n");
return 0;
P9: 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() {
int year;
scanf("%d", &year);
else
{
printf("%d is not a Leap Year.\n", year);
return 0;
Self Activity
1. Execute the following program for five different values and fill in the adjoining table
main()
int n;
printf(“Enter no.”);
scanf(“%d”,&n);
if(n% ==0)
printf(“divisible);
else
n output
2. Type the above sample program 4 and execute it for the following values.
n Output message
50
100
65
3. Using the sample code 3 above write the complete program to find the maximum of three