Monday, October 27, 2014

Find the Sum of G.P Series

Find the Sum of G.P Series
#include 
#include 
#include 
 
int main()
{
    float a, r, i, last_term, sum = 0;
    int n;
    clrscr();
    printf("Enter the first term of the G.P. series: ");
    scanf("%f", &a);
    printf("Enter the total numbers in the G.P. series: ");
    scanf("%d", &n);
    printf("Enter the common ratio of G.P. series: ");
    scanf("%f", &r);
    sum = (a *(1 - pow(r, n + 1))) / (1 - r);
    last_term = a * (1 - pow(r, n - 1));
    printf("last_term term of G.P.: %f", last_term);
    printf("\n Sum of the G.P.: %f", sum);
    return 0;
    getch();
}
 
 
 
 
Output
 
Enter the first term of the G.P. series: 3
Enter the total numbers in the G.P. series: 7
Enter the common ratio of G.P. series: 2
last_term term of G.P.: -189.000000
Sum of the G.P.: 765.000000
Find the Sum of H.P Series
#include 
#include  
void main()
{
    int n;
    float i, sum, term;
    clrscr();
    printf("1 + 1 / 2 + 1 / 3 +......+1 / n \n");
    printf("Enter the value of n \n");
    scanf("%d", &n);
    sum = 0;
    for (i = 1; i <= n; i++)
    {
        term = 1 / i;
        sum = sum + term;
    }
    printf("the Sum of H.P Series is = %f", sum);
    getch();
}
Output
 
1 + 1 / 2 + 1 / 3 +......+1 / n
Enter the value of n
5
the Sum of H.P Series is = 2.283334
Find Area of a Right Angled Triangle
#include 
#include 
int main()
{
    float height, width;
    float area;
    clrscr();
    printf("Enter height and width of the given triangle:\n ");
    scanf("%f%f", &height, &width);
    area = 0.5 * height * width;
    printf("Area of right angled triangle is: %.3f\n", area);
    return 0;
    getch();
}

Output
 
Enter height and width of the given triangle:
 10 15
Area of right angled triangle is: 75.000
Find Area of Trapezium
#include 
#include 
int main()
{
    float a, b, h;
    float area;
    clrscr();
    printf("Enter the value for two bases & height of the trapezium: \n");
    scanf("%f%f%f", &a, &b, &h);
    area = 0.5 * (a + b) * h ;
    printf("Area of the trapezium is: %.3f", area);
    return 0; 
    getch();
}

Output
 
Enter the value for two bases and height of the trapezium :
10 15 20
Area of the trapezium is: 250.000
Find Area of Rhombus
#include 
#include  
int main()
{
    float diagonal1, diagonal2;
    float area;
    clrscr();
    printf("Enter diagonals of the given rhombus: \n ");
    scanf("%f%f", &diagonal1, &diagonal2);
    area = 0.5 * diagonal1 * diagonal2;
    printf("Area of rhombus is: %.3f \n", area);
    return 0; 
    getch();
}
Output
 
Enter diagonals of the given rhombus:
 30 40
Area of rhombus is: 600.000
Find Area of Parallelogram
#include 
#include 
int main()
{
    float base, altitude;
    float area;
    clrscr();
   printf("Enter base and altitude of the given Parallelogram: \n ");
    scanf("%f%f", &base, &altitude);
    area = base * altitude;
    printf("Area of Parallelogram is: %.3f\n", area);
    return 0;
    getch();
}

Output
 
Enter base and altitude of the given Parallelogram:
 17 19
Area of Parallelogram is: 323.000
Find the Volume and Surface Area of Cuboids
#include 
#include 
#include 
 
int main()
{
    float width, length, height;
    float surfacearea, volume, space_diagonal;
 
   
   clrscr(); 
   printf("Enter value of width, length & height of the cuboids:\n");
    scanf("%f%f%f", &width, &length, &height);
    surfacearea = 2 *(width * length + length * height +
    height * width);
    volume = width * length * height;
    space_diagonal = sqrt(width * width + length * length +
    height * height);
    printf("Surface area of cuboids is: %.3f", surfacearea);
    printf("\n Volume of cuboids is : %.3f", volume);
    printf("\n Space diagonal of cuboids is : %.3f", space_diagonal);
    return 0;
    getch();
}

Output
 
Enter value of width, length & height of the cuboids :
 22 23 24
Surface area of cuboids is: 3172.000
Volume of cuboids is : 12144.000
Space diagonal of cuboids is : 39.862
Find the volume and surface area of cone
#include 
#include 
#include 
 
int main()
{
 
    float radius, height;
    float surface_area, volume;
    clrscr();
    printf("Enter value of radius and height of a cone :\n ");
    scanf("%f%f", &radius, &height);
    surface_area = (22 / 7) * radius * (radius + sqrt(radius * radius + height * height));
    volume = (1.0/3) * (22 / 7) * radius * radius * height;
    printf("Surface area of cone is: %.3f", surface_area);
    printf("\n Volume of cone is : %.3f", volume);
    return 0;
    getch();
}

Output
 
Enter value of radius and height of a cone :
 6 9
Surface area of cone is: 302.700
Volume of cone is : 324.000
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