Program to find area and circumference of circle based on choice in C

Logic:

  • Enter choice ch
  • Enter radius of circle as r
  • If ch=1, find area=pi * r * r
  • if ch=2 find circumference = 2 * pi * r
  • Otherwise print “Wrong Choice”

Algorithm

  1. Enter choice ch
  2. Enter radius of circle r
  3. if (ch == 1)
  4. {
  5. a = 3.14 * r * r;
  6. printf(“the area of circle is %d \n”, a);
  7. }
  8. else if (ch == 2)
  9. {
  10. c = 2 * 3.14 * r;
  11. printf(“the circumference of circle is %d”, c);
  12. }
  13. else
  14. printf(“wrong choice”);

Program

#include <stdio.h>
int main()
{
    printf("**********************************************************\n");
    printf("**********************************************************\n");
    printf("**     WAP to find area OR circumference of circle      **\n");
    printf("**           Created by Sheetal Garg                    **\n");
    printf("**            Assistant Professor                       **\n");
    printf("**            Phone No:9467863365                       **\n");
    printf("**********************************************************\n");
    printf("**********************************************************\n");
    float r, a, c;
    int ch;
    printf("enter the radius of circle \n ");
    scanf("%f", &r);
    printf("enter choice");
    scanf("%d", &ch);
    if (ch == 1)
    {
        a = 3.14 * r * r;
        printf("the area of circle is %f \n", a);
    }
    else if (ch == 2)
    {
        c = 2 * 3.14 * r;
        printf("the circumference of circle is %f", c);
    }
    else
        printf("wrong choice");
    return 0;
}

Output 1:

**********************************************************
**********************************************************
**     WAP to find area OR circumference of circle      **
**           Created by Sheetal Garg                    **
**            Assistant Professor                       **
**            Phone No:9467863365                       **
**********************************************************
**********************************************************
enter the radius of circle 
 7
enter choice
1
the area of circle is 153.860001 

Output 2:

**********************************************************
**********************************************************
**     WAP to find area OR circumference of circle      **
**           Created by Sheetal Garg                    **
**            Assistant Professor                       **
**            Phone No:9467863365                       **
**********************************************************
**********************************************************
enter the radius of circle 
 7
enter choice
2
the circumference of circle is 43.959999

Output 3:

**********************************************************
**********************************************************
**     WAP to find area OR circumference of circle      **
**           Created by Sheetal Garg                    **
**            Assistant Professor                       **
**            Phone No:9467863365                       **
**********************************************************
**********************************************************
enter the radius of circle 
 5
enter choice
3
wrong choice
error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.