Write an if/then.else primitive to do each of the following operations.
A. Computer and display the value x divided by y if the value of y is
not 0. If y does have the value 0, then display the message "unable
to perform the division."
B. Computer the area and circumference of a circle given the radius r
if the radius is greater than or equal to 1.0; otherwise, you should
compute only the circumference.
A.
/* This program is in 'c programming language save it with .c extension*/
#include
#include
void main()
{
float x,y,d;
clrscr();
printf("Enter any value for x and y :");
scanf("%f %f",&x,&y);
if(y==0)
printf("unable to perform the division.");
else
{
d=x/y;
printf(" Division = %f",d);
}
getch();
}
B.
/* This program is in 'c programming language save it with .c extension*/
#include COMFY---A Comfortable Set of Control Primitives for Machine :: Actions are primitive instructions executed for their side-effects such as If-then-else Before trying to simulate the construct "if B then A else C" in http://home.pipeline.com/~hbaker1/sigplannotices/COMFY.TXTHOME | Extending DTG with Options:: File Format: PDF/Adobe Acrobat - View as HTMLDepartment of Computer Science. RWTH Aachen. ferrein, fritz, gerhard @cs.rwth- aachen.de grams using the usual constructs like sequence, if-then-else, http://reference.kfupm.edu.sa/content/e/x/extending_dtgolog_with_options__103363.pdfHOME |
#include
void main()
{
float radius,area,circum;
clrscr();
printf("Enter any value for radius:");
scanf("%f",&radius);
if(radius>=1.0)
{
area=3.14*radius*radius;
circum=2*3.14*radius;
printf("area = %f and circumference = %f",area,circum);
}
else
{
circum=2*3.14*radius;
printf("circumference = %f",circum);
}
getch();
} Symbolic Test Case Generation for Primitive Recursive Functions:: File Format: PDF/Adobe Acrobat - View as HTMLnested “if then else” constructs. Their decomposition during .. Theoretical Computer Science, Roros, 2003. Elsevier Science Publishers. http://www.brucker.ch/bibliography/download/2005/brucker.ea-symbolic-2005.pdfHOME | COT 3002 syllabus:: May 13, 2002 Basic concepts of computer science; C++ I/O, simple classes (private & public) and types; if/else, operators, value-returning functions, http://www.cse.fau.edu/~roy/cot3002.02c/syllabus.htmlHOME |
A.
if (y !=0)
printf ("%f", x/y)
else
printf ("unable to perform the division.");
B.
if (r >= 1.0)
printf ("area: %fn", 2*pi*r);
printf ("circumference: %f", pi*r*r);
//The following is written in C++
#include
using namespace std;
void partA(double x, double y)
{
if(y != 0)
cout << (x / y) << endl;
else
cout << "unable to perform the division." << endl;
}
void partB(double r)
{
double results = 0.0;
double const PI = 3.14159;
if(r >= 1.0) cout << "Radius = " << (PI * r * r) << endl;
cout << "Circumference = " << (2 * r * PI) << endl;
}
Where was the last debate on wednesday with Mccain and Obama?
INSTANCE / WAITING FOR SPRING
|