WAP program to find area of the circle, Write a C or C++ program to find area of the circle using math.h function & defining constant with output
Program
#include<math.h>
#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main()
{
float a,b;
clrscr();
printf("enter the radius of the circle");
scanf ("%f", &a);
b=pi*a*a;
printf("area is");
printf("%f", b);
getch();
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
Program
#include<math.h>
#include<stdio.h>
#include<conio.h>
#define pi 3.14
void main()
{
float a,b;
clrscr();
printf("enter the radius of the circle");
scanf ("%f", &a);
b=pi*a*a;
printf("area is");
printf("%f", b);
getch();
}
Changes for C++
If you want to write the same program in c++ apply the following changes to the program.
1.) change the header file from "#include<stdio.h>" to "#include<iostream>.h"
2.) for input & output use "cout<<" & "cin>>" instead of "printf" & "scanf".
3.) don't use "% "symbol and "&" sign in "cin>>" statement.
Click here to check the output
No comments:
Post a Comment