Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
Answer:
Step 1: set L=b=r=h=a=2
Step 2: Display-enter length &breadth of rectangle
Step 3: read in L&b
Step 4: Display-enter height&base of triangle
Step 5: read in h&b
Step 6: Display-enter radius of circle
Step 7: read in r
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).?
Answer:
Start
Rectangle
Triangle
circle
Read in “n”
n=?
Set L=B=A=1
Set r=A=1 Set B=h=A=1
Read b Read L
Read r
and h and 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.
Answer:
Start
Set n=a=1
Print 1.rectangle
2. Triangle
3. Circle
Read n
If n=1
(Read L and b
Set a=L*b)
Else
If n=2
(Read b and h
Set A =1/2*b*h)
Else
(Read r
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.?
Answer:
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if (a==b&&b==c)
else
if(a==b||a==c||b==c)
else
if(a!=b&&a!=c&&b!=c)
Else
#include<conio.h>
void main()
int a,r,h,vol_cub,ch;
float vol_sph,vol_cy;
clrscr();
scanf(“%d”,&ch);
if(ch==1)
scanf(“%d”,&a);
vol_cub=a*a*a;
printf(“\nVolume= %d”,vol_cub);
else if(ch==2)
{
printf(“\nEnter radius of sphere: “);
scanf(“%d”,&r);
else if(ch==3)
scanf(“%d”,&r);
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 ‘+’ , ’-’ , ’*’ & ‘/’?
Answer:
#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 1. addition\
\n 2. substraction\
\n 3. multiplication\
\n 4. division");
scanf("%d",&n);
switch(n)
{
case 1:
{printf("\n addition:%d",a+b);
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();
}