Wednesday, March 2, 2011

1

C Program Language (Area Of Circle, Triangle and Square)

  • Wednesday, March 2, 2011
  • RJ
  • Share
  • These program will be tackling about the area of a circle, triangle and square. We all know that to get the area of  those shapes we must identify first the formulas to used. Now here are the formulas

    Circle
    Area = πr2
    Circumference=2πr
    r = radius
    Triangle
    Area = ½b × h
    b = base
    h = vertical height
    Square
    Area = a2
    a = length of side

    After getting the formulas we have to use it in the program. The program will ask the user what area should find either circle, triangle or square. Then the program will ask the user the given and the program will show the answers. The program also will ask the user to repeat again or terminate the program. The output will be shown below.


    Getting the area of Circle

    Getting the area of Triangle

    Getting the area of Square
    Now that you have seen the outputs for the program you will be puzzled how to get it. It is so simple because all you have to do is add the formulas to the program like these one. The codes for the area of circle,triangle and square.





    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    main()
    {
    int n1;
    int sum;
    int a,b,c;
    char y,s;
    
    printf("Enter Operation To be Used: \n");
    printf("(1=circle   2=Triangle   3=Square): ");
    scanf("%d",&n1);
    
    
    
    float pi;
    
    switch(n1)
    {
    case 1:
    
    float rad;
    printf("\n\nArea Of a Circle!");
    printf("\nEnter radius: ");
    scanf("%f",&rad);
    
    float areac;
    areac = (3.14) * (rad * rad);
    
    printf("The Area of a circle is %.2f",areac);
    break;  
    
    
    
    
    case 2:          
    
    int base,he,areat;
    
    printf("\n\nArea Of a Triangle!");
    printf("\nEnter base: ");
    scanf("%d",&base);
    printf("Enter height: ");
    scanf("%d",&he);
    
    areat = (base * he)/(2);
    
    printf("The Area of a triangle is %d",areat);
    break;
    
    
    
    
    case 3:     
    int side,areas;
    printf("\n\nArea Of a Square!");
    printf("\nEnter side: ");
    scanf("%d",&side);
    
    
    areas = side * side;
    
    printf("The Area of a Square is %d",areas);
    break;
    }        
    if(n1>=4)
    {
    printf("\nInvalid Input!");
    
    }      
    
    printf("\n\nPress Y to repeat and N to end:\n");
    scanf("%s",&s);
    if(s=='y'){
    system ("cls");
    return main();        
    getch();
    }
    
    if (s=='y')
    {
    return 0;
    }}

    1 Responses to “C Program Language (Area Of Circle, Triangle and Square)”

    Unknown said...
    August 10, 2012 at 4:57 AM

    Thanks...that is useful much..!!!


    Post a Comment

    Subscribe