Professional Documents
Culture Documents
Assignment-X: Q1. Write A Program To Swap Two Number Using Pointer/call by Reference. Answer
Assignment-X: Q1. Write A Program To Swap Two Number Using Pointer/call by Reference. Answer
}
int main()
{
int num;
printf("Enter the number ");
scanf("%d",&num);
printf("The factorial is %d \n",factorial(num));
return 0;
}
Q3. Write a program to find area of circle, rectangle, square, and triangle
using function.
Answer:
// area of circle rectangle square and triangle
#include <stdio.h>
#include <math.h>
int area;
void square(int s)
{
area = s * s;
printf("The area of the square having side %d is %d \n", s,
area);
}
void rectangle(int l, int b)
{
area = l * b;
printf("The area of the rectangle having length %d and breadth
%d is %d \n", l, b, area);
}
void circle(int r)
{
const float PI = 3.14;
area = PI * r * r;
printf("The area of the circle having radius %d is %d \n", r,
area);
}
void triangle(int s1, int s2, int s3)
{
int s;
s = (s1 + s2 + s3) / 2;
area = sqrt((s * (s - s1) * (s - s2) * (s - s3)));
printf("The area of the triangle having sides %d %d %d is %d
\n", s1, s2, s3, area);
}
int main()
{
int choice;
break;
case 2:
{
int side;
printf("Enter the length of the side of the square ");
scanf("%d", &side);
square(side);
}
break;
case 3:
{
int length, breadth;
printf("Enter the length of the side of the rectangle
");
scanf("%d", &length);
printf("Enter the breadth of the side of the rectangle
");
scanf("%d", &breadth);
rectangle(length, breadth);
}
break;
case 4:
{
int s1, s2, s3;
printf("Enter the length of the first side of the
triangle ");
scanf("%d", &s1);
printf("Enter the length of the second side of the
triangle ");
scanf("%d", &s2);
printf("Enter the length of the third side of the
triangle ");
scanf("%d", &s3);
triangle(s1, s2, s3);
}
break;
deafult:
{
printf("You have entered an incorrect choice \n");
}
}
return 0;
}