You are on page 1of 4

Lab No:05

Title: Decision Control Structure (Simple Without nesting).

Objective:

Introduction:

Post Lab Tasks:


Task 1:
Given the length and breadth of a rectangle, write a program to find whether the area of the
rectangle is greater than its perimeter, less than its parameter and equal to its parameter. For
example, the area of the rectangle with length = 5 and breadth = 4 is greater than its perimeter
(using if else and else if)

Solution:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int length, breadth, perimeter, area;

printf("Enter length and breadth: ");


scanf("%d%d", &length, &breadth);

area = length*breadth;
perimeter = 2 * (length + breadth);

printf("Area is : %d",area);
printf("\nPerimeter is : %d",perimeter);

if (area>perimeter)
printf("\nArea is greater than perimeter");
else if (area<perimeter)
printf("Area is lesser than perimeter");
else
printf("Area and perimeter are equal");

return 0;
}
Task 2:
Write a program to find out area of circle, rectangle, square and triangle through if else
statement.
(Input a character check if character is c than calculate the area of circle, if character is t then
calculated the area of a triangle and so on. If a user enters invalid character then it should display
invalid choice.)
(using if else and else if)

Solution:
#include <stdio.h>
#include <stdlib.h>

int main()
{
char area;
printf("\n\t Enter The value of area: \n\t");
scanf("%c",&area);
if (area == 'c')
printf("\n\t Will Calculate area of Circle: \n\t");

{
float area_of_circle;
int R;
scanf("%d",&R);
area_of_circle = 3.14*(R*R);
printf("\n\t area of circle = %.2f \n\t",area_of_circle);
}

if (area == 's')
printf("\n\t Will Calculate area of Square: \n\t");

{
float area_of_square;
int a;
scanf("%d",&a);
area_of_square = a*a;
printf("\n\t area of square = %.2f \n\t",area_of_square);
}

if (area == 't')
printf("\n\t Will Calculate area of Traingle: \n\t");

{
float area_of_traingle;
int B,H;
scanf("%d %d",&B,&H);
area_of_traingle = (B*H)/2;
}

if (area == 'r')
printf("\n\t Will calculate area of Rectangle: \n\t");

{
float area_of_rectangle;
int L,W;
scanf("%d %d",&L,&W);
area_of_rectangle = L*W;
printf("\n\t area of rectangle = %.2f
\n\t",area_of_rectangle);
}

return 0;
#include <stdio.h>
#include <stdlib.h>

int main()
{
int y;
printf("\n\t Enter the value Y: \n\t");
scanf(" %d ",&y);

if (y%4== 0)
printf("\n\t Year Is leap: \n\t");
else
printf("\n\t Common Year \n\t");
return 0;

You might also like