IT22111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY
EX.NO:
DATE:
SCIENTIFIC PROBLEM SOLVING USING DECISION MAKING
QUESTION:2a
Read the age of a person and check of the person is eligible to vote (>
18 years
AIM:
ALGORITHM:
Roll Number: Page No.:
PROGRAM:
#include<stdio.h>
int main()
{
int age;
printf("enter age");
scanf("%d",&age);
if(age>=18)
printf("the person is eligible to vote");
else
printf("not eligible to vote");
}
SAMPLE INPUT AND OUTPUT:
[cs24a039@CO478 ~]$ vi ex3a.c
[cs24a039@CO478 ~]$ cc ex3a.c
[cs24a039@CO478 ~]$ ./a.out
enter age 19
the person is eligible to vote
RESULT:
Roll Number: Page No.:
QUESTION:2b
Write a C program to check if a year is leap or not
AIM:
ALGORITHM:
Roll Number: Page No.:
PROGRAM:
#include<stdio.h>
int main()
{int year,month;
printf("enter year");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
{printf("%dit is a leap year",year);
}
else
{printf("%dit is not a leap year",year);
}
return 0;
}
SAMPLE INPUT AND OUTPUT:
[cs24a039@CO478 ~]$ vi 3b.c
[cs24a039@CO478 ~]$ cc 3b.c
[cs24a039@CO478 ~]$ ./a.out
enter year 2024
it is a leap year
RESULT:
Roll Number: Page No.:
QUESTION:2c
Ram, Balaji, and Kumar are siblings aged x,y, and z respectively. Find
theyoungest and oldest among them.
AIM:
ALGORITHM:
Roll Number: Page No.:
PROGRAM:
#include<stdio.h>
int main()
{
int x,y,z;
printf("enter the age of ram,balaji,kumar");
scanf("%d%d%d",&x,&y,&z);
if(x<y&&x<z)
printf("ram is youngest");
else if(y<x&&y<z)
printf("balaji is youngest");
else
printf("kumar is youngest");
if(x>y&&x>z)
printf("ram is eldest");
else if(y>x&&y>z)
printf("balaji is eldest");
else
printf("kumar is eldest");
}
SAMPLE INPUT AND OUTPUT:
[cs24a039@CO478 ~]$ vi 3c.c
[cs24a039@CO478 ~]$ cc 3c.c
[cs24a039@CO478 ~]$ ./a.out
enter the age of ram,balaji,kumar 20 25 30
ram is youngestkumar is eldest
RESULT:
Roll Number: Page No.:
QUESTION:2d
‘Solar System’ is an application that reads a number between 1 and 9 and
prints the respective planet. For example, if it reads 3, it displays ‘Venus’.
Develop the application Solar System. (simple switch)
AIM:
ALGORITM:
Roll Number: Page No.:
PROGRAM:
#include<stdio.h>
int main()
{
int num;
printf("enter a num");
scanf("%d",&num);
switch(num)
{
case 1:
printf("mercury");
break;
case 2:
printf("venus");
break;
case 3:
printf("earth");
break;
case 4:
printf("mars");
break;
case 5:
printf("jupiter");
break;
case 6:
printf("saturn");
break;
case 7:
printf("uranus");
break;
case 8:
printf("neptune");
break;
case 9:
printf("pluto");
Roll Number: Page No.:
break;
default:
printf("the number is invalid");
}
}
SAMPLE INPUT AND OUTPUT:
[cs24a039@CO478 ~]$ vi 3d.c
[cs24a039@CO478 ~]$ cc 3d.c
[cs24a039@CO478 ~]$ ./a.out
enter a num 3
earth
RESULT:
Roll Number: Page No.:
QUESTION:2e
Read the marks scored by a student in a subject and calculate the grade
using the above grading system.
Grade O S A B C D
Mark
100 90-99 80-89 70-79 60-69 50-59
range
AIM:
ALGORITHM:
Roll Number: Page No.:
PROGRAM:
#include <stdio.h>
int main() {
int marks;
char grade;
printf("enter the marks scored by students ");
scanf("%d",&marks);
if(marks==100)
{grade='O';
}
else if(marks>=90&&marks<=99)
{grade='S';
}
else if(marks>=80&&marks<=89)
{grade='A';
}
else if(marks>=70&&marks<=79)
{grade='B';
}
else if(marks>=60&&marks<=69)
{grade='C';
}
else if(marks>=50&&marks<=59)
{grade='D';
}
else
{grade='F';
}
printf("the grade of the students is %c",grade);
return 0;
}
Roll Number: Page No.:
SAMPLE INPUT AND OUTPUT:
[cs24a039@CO478 ~]$ vi 3c.c
[cs24a039@CO478 ~]$ cc 3c.c
[cs24a039@CO478 ~]$ ./a.out
enter the marks scored by students 90
the grade of the students is S
RESULT:
Roll Number: Page No.: