236c

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Amrita School of Computing

23CSE201– Procedural
programming using C
BACHELOR OF TECHNOLOGY

IN
COMPUTER SCIENCE AND
ENGINEERING

BY – PULLELA SURARCHITHA
CH.SC.U4CSE23236
Exercise-1:

IF-ELSE Statements:
1) Write a C program for analysis of people of certain age
groups who are eligible for getting a suitable job if their
condition and norms get satisfied using nested if statement.
(age should be between 18 and 57)

Code:
#include<stdio.h>
int main(){
int x;
char s;
printf("Enter your age:\n");
scanf("%d",&x);
if(x>=18 && x<=57){
printf("Your age is eligible for job\n");
printf("Do you have any health conditions Y/N :\n");
getchar();
scanf("%c",&s);
if(s=='Y' || s=='y'){
printf("You are eligible for job\n");
}
else{
printf("You are not eligible for job\n");
}
}
else{
printf("Your age is not eligible for job \n");
}
printf("CH.SC.U4CSE23236");
}

Output:
2)Write a C program to check if three numbers are
equal or not

Code:
#include<stdio.h>
int main(){
int x,y,z;
printf("Enter 3 numbers");
scanf("%d %d %d",&x, &y, &z);
if(x==y && y==z){
printf("All three numbers are same %d %d
%d",x,y,z);
}
else{
printf("%d %d %d are not same",x,y,z);
}
printf("CH.SC.U4CSE23236");
}

Output:

3)Write a C program to find the max among three


numbers

Code:
#include<stdio.h>
int main(){
int x,y,z;
printf("Enter 3 numbers");
scanf("%d %d %d",&x,&y,&z);
if(x>y && x>z){
printf("%d is max of all\n",x);
}
else if(y>x && y>z){
printf("%d is max of all\n",y);
}
else{
printf("%d is max of all\n",z);
}
printf("CH.SC.U4CSE23236");
}

Output:
4)Write a C program to print if the given integer
number is even and divisible by 6.

Code:
#include<stdio.h>
main(){
int x;
printf("Enter a number:\n");
scanf("%d",&x);
if(x%2==0 && x%6==0){
printf("%d is even and divisible by 6\n",x);
}
else{
printf("%d is either not even or divisible by 6 \n",x);
}
}

Output:
5)Write a C program to print the number of days for
a given month (month: integer)

Code:
#include<stdio.h>
main(){
int x;
printf("Enter a month(1-12):\n");
scanf("%d",&x);
if(x==1){
printf("January has 31 days\n");
}
else if(x==2){
printf("February has 28 days\n");
}
else if(x==3){
printf("March has 31 days\n");
}
else if(x==4){
printf("April has 30 days\n");
}
else if(x==5){
printf("May has 31 days\n");
}
else if(x==6){
printf("June has 30 days\n");
}
else if(x==7){
printf("July has 31 days\n");
}
else if(x==8){
printf("August has 31 days\n");
}
else if(x==9){
printf("September has 30 days\n");
}
else if(x==10){
printf(" October has 31 days\n");
}
else if(x==11){
printf("November has 30 days\n");
}
else if(x==12){
printf("December has 31 days\n");
}
else{
printf("Enter a number between 1-12\n");
}

Output:
6)Write a C program to print if the given character is
alphabet or not

Code:
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
printf("'%c' is an alphabet.\n", ch);
} else {
printf("'%c' is not an alphabet.\n", ch);
}
return 0;
}
Output:

7)Write a C program to print the grade for the subject


based on the following criteria. 91-100 : O, 81-90: A ,71-
80:B ,61-70:C, 50-60: D, <50:F.

Code:
#include<stdio.h>
main(){
int x;
printf("Enter marks in Maths(0-100):\n ");
scanf("%d",&x);
if(x>=91 && x<=100){
printf("O grade\n");
}
else if(x>=81 && x<=90){
printf("A grade\n");
}
else if(x>=71 && x<=80){
printf("B grade\n");
}
else if(x>=61 && x<=70){
printf("C grade\n");
}
else if(x>=50 && x<=60){
printf("D grade\n");
}
else if(x<50 && x>0){
printf("F grade\n");
}
else{
printf("Enter marks between 0-100\n");
}
}

Output:
8)Write a C program to check whether a year is leap year
or not.

Code:
#include<stdio.h>
main(){
int x;
printf("Enter a year: \n");
scanf("%d",&x);
if(x%4==0 && x%100!=0){
printf("%d is a leap year\n",x);
}
else{
printf("%d is not a leap year\n",x);
}
}

Output:
9)Write a C program to input basic salary of an employee
and calculate its Gross salary according to following:
Basic Salary <= 10000 : HRA = 20% of basic salary, DA = 80% of
basic salary Basic Salary <= 20000 : HRA = 25% of basic salary,
DA = 90% of basic salary Basic Salary > 20000 : HRA = 30% of
basic salary, DA = 95% of basic salary
Gross Salary = Basic Salary + HRA +DA

Code:
#include<stdio.h>
main(){
int bs,hra,da,gs;
printf("Enter Salary amount:\n");
scanf("%d",&bs);
if(bs>=10000 && bs>=0){
hra=0.2*bs;
da=0.8*bs;
}
else if(bs>=20000 && bs=<10000){
hra=0.4*bs;
da=0.9*bs;
}
else if(bs>20000){
hra=0.3*bs;
da=0.95*bs;
}
else{
printf("Enter a correct amount(>0)\n");
}
gs=bs+hra+da;
printf("Gross salary for basic salary of %d is: %d\n",bs,gs);
}
Output:

10)Write a C program to input electricity unit charges


and calculate total electricity bill according to the given
condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill

Code:
#include<stdio.h>

main(){
int x,y;
float puc,tot;
printf("Enter units used:\n");
scanf("%d",&x);
if(x<=50){
puc=0.50*x;
}
else if(x>=50 && x<=150){
y=x-50;
puc=25+0.75*y;
}
else if(x>=150 && x<=250){
y=x-150;
puc=25+75+1.20*y;
}
else{
y=x-250;
puc=25+75+120+y;
}
printf("%f\n",puc);
tot=0.2*puc+puc;
printf("%f\n",tot);

Output:
DONE BY:
PULLELA SURARCHITHA
CH.SC.U4 CSE23236

You might also like