Monday, January 5, 2015

Surface Area of Sphere and Circle, Rectangle and Triangleand Floyd’s triangle in c pro



Find Volume and Surface Area of Sphere
 
#include 
#include 
#include 
int main()
{
    float radius;
    float surface_area, volume;
    clrscr();
    printf("Enter radius of the sphere : \n");
    scanf("%f", &radius);
    surface_area =  4 * (22/7) * radius * radius;
    volume = (4.0/3) * (22/7) * radius * radius * radius;
    printf("Surface area of sphere is: %.3f", surface_area);
    printf("\n Volume of sphere is : %.3f", volume);
    return 0;
    getch();
}
 
Output
 
Enter radius of the sphere :
40
Surface area of sphere is: 19200.000
Volume of sphere is : 256000.000
 
Find the Perimeter of a Circle, Rectangle and Triangle
 
#include 
#include 
#include 
int main()
{
    float radius, length, width, a, b, c, height;
    int n;
    float perimeter;
    clrscr();
    printf(" \n Perimeter of rectangle \n");
    printf("---------------------------\n");
    printf("\n Enter width and length of the rectangle : ");
    scanf("%f%f", &width,& length);
    perimeter = 2 * (width + length);
    printf("Perimeter of rectangle is: %.3f", perimeter);
                printf("\n Perimeter of triangle n");
    printf("---------------------------n");
    printf("\n Enter the size of all sides of the triangle : ");
    scanf("%f%f%f", &a, &b, &c);
    perimeter = a + b + c;
    printf("Perimeter of triangle is: %.3f", perimeter);
    printf(" \n Perimeter of circle \n");
    printf("---------------------------\n");
    printf("\n Enter the radius of the circle : ");
    scanf("%f", &radius);
    perimeter = 2 * (22 / 7) * radius;
    printf("Perimeter of circle is: %.3f", perimeter);
    printf(" \n Perimeter of equilateral triangle \n");
    printf("---------------------------\n");
    printf("\n Enter any side of the equilateral triangle : ");
    scanf("%f", &a);
    perimeter = 3 * a;
    printf("Perimeter of equilateral triangle is: %.3f", perimeter);
    printf(" \n Perimeter of right angled triangle \n");
    printf("---------------------------\n");
    printf("\n Enter the width and height of the right angled triangle : ");
    scanf("%f%f", &width, &height);
    perimeter = width + height + sqrt(width * width + height * height);
    printf("Perimeter of right angled triangle is: %.3f", perimeter);
    return 0;
    getch();
}

Output
 
Perimeter of rectangle
---------------------------
Enter width and length of the rectangle : 12 13
Perimeter of rectangle is: 50.000
Perimeter of triangle
---------------------------
Enter the size of all sides of the triangle : 12 16 18
Perimeter of triangle is: 46.000
Perimeter of circle
---------------------------
            Enter the radius of the circle : 10
Perimeter of circle is: 60.000
Perimeter of equilateral triangle
---------------------------
 
Enter any side of the equilateral triangle : 19 34
Perimeter of equilateral triangle is: 57.000
Perimeter of right angled triangle
---------------------------
Enter the width and height of the right angled triangle : 5 7
Perimeter of right angled triangle is: 73.366

Display Floyd’s triangle
 
#include 
#include 
main( )
{
    int i, j, k = 1;
    clrscr();
    printf("floyds triangle is\n");
    for( i = 1; k <= 20; ++i )
    {
        for( j = 1; j <= i; ++j )
                printf( "%d ", k++ );
                printf( "\n\n" );
    }
    return 0; 
   getch();
}

Output
 
Floyds triangle is
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21


No comments:

Post a Comment