COMPUTER SCIENCE
BASIC C PROGRAMMING CODES
1. Write a c program to check whether a number is divisible by 5 and 11 or not.
#include <stdio.h>
int main()
{
int num;
printf("Enter any number: ");
scanf("%d", &num);
if((num % 5 == 0) && (num % 11 == 0))
{
printf("Number is divisible by 5 and 11");
}
else
{
printf("Number is not divisible by 5 and 11");
}
return 0;
}
2.Write a C program to check whether a year is a leap year or not.
#include <stdio.h>
int main()
{
int year;
printf("Enter year : ");
scanf("%d", &year);
if(((year % 4 == 0) && (year % 100 !=0)) || (year % 400==0))
{
printf("LEAP YEAR");
}
else
{
printf("Not a Leap YEAR");
}
return 0;
}
,3.Write a c program to check whether a character is an alphabet or not.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("Character is an ALPHABET.");
}
else
{
printf("Character is NOT ALPHABET.");
}
return 0;
}
4.Write a c program to input any alphabet and check whether it is vowel or consonant.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' ||
ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
printf("'%c' is Vowel.", ch);
}
else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is Consonant.", ch);
}
else
{
printf("'%c' is not an alphabet.", ch);
}
, return 0;
}
5.Write a program to check whether it is an alphabet, digit or special character.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
6.Write a c program to input the basic salary of an employee and calculate its gross
salary according to the following:
Basic Salary <= 10000: HRA = 20%, DA = 80%
Basic Salary <= 20000: HRA = 25%, DA = 90%
Basic Salary >20000: HRA = 30%, DA = 95%
#include <stdio.h>
int main()
{
float basic, gross, da, hra;
printf("Enter basic salary of an employee: ");
scanf("%f", &basic);
if(basic <= 10000)
{
da = basic * 0.8;
hra = basic * 0.2;
}
, else if(basic <= 20000)
{
da = basic * 0.9;
hra = basic * 0.25;
}
else
{
da = basic * 0.95;
hra = basic * 0.3;
}
gross = basic + hra + da;
printf("GROSS SALARY OF EMPLOYEE = %.2f", gross);
return 0;
}
7.Write a c program to get an input values x and y, and print x is greater than y.
#include <stdio.h>
int main()
{
int x, y;
printf(“Enter the value of x and y: \n”);
scanf(“%d%d”, &x,&y);
if (x>y)
{
printf("Variable x is greater than y");
}
return 0;
}
8. Write a c program to check the given number is positive or negative with if…else
statement
#include <stdio.h>
int main()
{
int a;
printf("Enter the number a \n");
scanf("%d", &a);
if (a>=0)
{
printf("The value %d is positive number",a);
BASIC C PROGRAMMING CODES
1. Write a c program to check whether a number is divisible by 5 and 11 or not.
#include <stdio.h>
int main()
{
int num;
printf("Enter any number: ");
scanf("%d", &num);
if((num % 5 == 0) && (num % 11 == 0))
{
printf("Number is divisible by 5 and 11");
}
else
{
printf("Number is not divisible by 5 and 11");
}
return 0;
}
2.Write a C program to check whether a year is a leap year or not.
#include <stdio.h>
int main()
{
int year;
printf("Enter year : ");
scanf("%d", &year);
if(((year % 4 == 0) && (year % 100 !=0)) || (year % 400==0))
{
printf("LEAP YEAR");
}
else
{
printf("Not a Leap YEAR");
}
return 0;
}
,3.Write a c program to check whether a character is an alphabet or not.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("Character is an ALPHABET.");
}
else
{
printf("Character is NOT ALPHABET.");
}
return 0;
}
4.Write a c program to input any alphabet and check whether it is vowel or consonant.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' ||
ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
printf("'%c' is Vowel.", ch);
}
else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is Consonant.", ch);
}
else
{
printf("'%c' is not an alphabet.", ch);
}
, return 0;
}
5.Write a program to check whether it is an alphabet, digit or special character.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
6.Write a c program to input the basic salary of an employee and calculate its gross
salary according to the following:
Basic Salary <= 10000: HRA = 20%, DA = 80%
Basic Salary <= 20000: HRA = 25%, DA = 90%
Basic Salary >20000: HRA = 30%, DA = 95%
#include <stdio.h>
int main()
{
float basic, gross, da, hra;
printf("Enter basic salary of an employee: ");
scanf("%f", &basic);
if(basic <= 10000)
{
da = basic * 0.8;
hra = basic * 0.2;
}
, else if(basic <= 20000)
{
da = basic * 0.9;
hra = basic * 0.25;
}
else
{
da = basic * 0.95;
hra = basic * 0.3;
}
gross = basic + hra + da;
printf("GROSS SALARY OF EMPLOYEE = %.2f", gross);
return 0;
}
7.Write a c program to get an input values x and y, and print x is greater than y.
#include <stdio.h>
int main()
{
int x, y;
printf(“Enter the value of x and y: \n”);
scanf(“%d%d”, &x,&y);
if (x>y)
{
printf("Variable x is greater than y");
}
return 0;
}
8. Write a c program to check the given number is positive or negative with if…else
statement
#include <stdio.h>
int main()
{
int a;
printf("Enter the number a \n");
scanf("%d", &a);
if (a>=0)
{
printf("The value %d is positive number",a);