Вы находитесь на странице: 1из 9

Homework Title / No…….1…….

Course Instructor: Harsimran Singh Course Tutor (if applicable):

____________

Date of Allotment: 21st Jan Date of submission: 1st Feb Student’s Roll No.A19
Section No. : G6005
Declaration:
I declare that this assignment is my individual work. I have not copied from any
other student’s work or from any other source except where due acknowledgment is
made explicitly in the text, nor has any part been written for me by another person.

Student’s Signature: Vishwas

____________________________________________________________________
_
Marks obtained: ___________ out of ______________________
Q. 1 Write an algorithm to calculate area of rectangle, circle & triangle. An algorithm should be
designed in such a way that user must be able to see the list of various geometric shapes
available. There must be clear statements to take input & display computed area. Result should
be in clear format with integrity. Overall it should be user friendly. ?

Step 1: set L=b=r=h=a=2
Step 2: Display-enter length &breadth of rectangle
Step 4: Display-enter height&base of triangle
Step 6: Display-enter radius of circle
Step 8: Display- Area of a rectangle=L*b
Step 9: Display- Area of a triangle=1/2*b*h
Step 10: Display- Area of a circle=3.14*r*r
Step 11: exist
Q. 2 Design the flowchart of the problem mentioned in Q1. While designing the flow chart, you
need to add little more functionality as follows like out of the list of various geometric shapes
available user may be able to calculate area for only one selected shape at a time (using Decision
Logic).?

Start

Rectangle

Triangle

circle

n=?

Set L=B=A=1
Set r=A=1 Set B=h=A=1

and h and b

A=3.14*r*r A=1/2*B*H A=L*B

Display
Area

ST
OP
Q. 3 After implementing the flowchart in Q2, you are required to generate Pseudo code for the
same. Pseudo code must satisfy all the checks and constraints mentioned above.

Start
Set n=a=1
Print 1.rectangle
2. Triangle
3. Circle
If n=1
Set a=L*b)
Else
If n=2
Set A =1/2*b*h)
Else
Set A =3.144*r*r)
Print Area
Stop.
Q. 4 Basically there are three types of triangles: Equilateral, Isosceles & Scalene. Write a
program to input three sides of a triangle & then check that which out of these three categories
your triangle belongs to. Also check that only valid inputs must be accepted by the code.?

#include<stdio.h>

#include<conio.h>

#include<math.h>

main()

int a,b,c;

printf("enter the three sides of triangle");

scanf("%d%d%d",&a,&b,&c);

if (a==b&&b==c)

{printf("The triangle is equilateral");}

else

if(a==b||a==c||b==c)

{printf("The triange is isoceles");}

else

if(a!=b&&a!=c&&b!=c)

Else

{printf("invalid input found");}getch();

Q. 5 Write a program to compute the volume of cube, sphere & cylinder; with the help of the
program, you are required to demonstrate the difference between variables and constants also.
This program must contain all types of variables and constants possible in C Language. Every
constant must be initialized and for every variable, user must enter the value at runtime. Test
conditions are required to be given for the code. No irrelevant data should be accepted in any
case. Output should be generated as a Report with following information; Object Name, Variable
Name1, Variable Name2….Variable Name N, Variable Types, Variable Size (Memory) in bytes,
Values entered by the user and result.

#include<stdio.h>

#include<conio.h>

void main()

int a,r,h,vol_cub,ch;

float vol_sph,vol_cy;

clrscr();

scanf(“%d”,&ch);

if(ch==1)

printf(“\nEnter side of cube: “);

scanf(“%d”,&a);

vol_cub=a*a*a;

printf(“\nVolume= %d”,vol_cub);

else if(ch==2)

{

scanf(“%d”,&r);

else if(ch==3)

scanf(“%d”,&r);

printf(“\nEnter height of cylinder: “);

scanf(“%d”,&h);

vol_cy=pi*r*r*h;

else

{}

getch();

}
Q. 6 Create a Menu driven program using switch statement to perform arithmetic
operations by defining cases for characters ‘+’ , ’-’ , ’*’ & ‘/’?

#include<stdio.h>
#include<conio.h>
main ()
{
Int n, a,b,c;
printf ("enter the values of a and b");
scanf("%d%d",&a,&b);
printf("\n what to do?\
\n 2. substraction\
\n 3. multiplication\
\n 4. division");
scanf("%d",&n);
switch(n)
{
case 1:
break;
}
case 2:
{ printf("\n substraction:%d",a-b);
break;
}
case 3:
{ printf("\n multiplication:%d",a*b);
break;
}
case 4:
{
if (b==0)
{printf("divide by zero error");
break;}
else{
printf("division:%d",b/a);
break;
}
}
{
default:
{
printf("non sense value");
}
}
}
getch();
}