Monday, January 5, 2015

C using Hp series and Right Angled Triangle and Area of Trapezium pro



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

No comments:

Post a Comment