Google Answers Logo
View Question
 
Q: Computer Science (if/then/else primitive) ( No Answer,   3 Comments )
Question  
Subject: Computer Science (if/then/else primitive)
Category: Computers
Asked by: jtallen7-ga
List Price: $2.00
Posted: 13 Feb 2005 15:40 PST
Expires: 15 Mar 2005 15:40 PST
Question ID: 473998
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.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Computer Science (if/then/else primitive)
From: khoatran-ga on 13 Feb 2005 17:35 PST
 
A.
if (y !=0)
  printf ("%f", x/y)
else
  printf ("unable to perform the division.");

B.
if (r >= 1.0)
  printf ("area: %f\n", 2*pi*r);
printf ("circumference: %f", pi*r*r);
Subject: Re: Computer Science (if/then/else primitive)
From: aquatopia-ga on 28 Feb 2005 01:49 PST
 
//The following is written in C++
#include <iostream>

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;
}
Subject: Re: Computer Science (if/then/else primitive)
From: inmar2002-ga on 08 Mar 2005 05:37 PST
 
A. 
/* This program is in 'c programming language  save it with .c extension*/
#include <stdio.h>
#include <conio.h>
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 <stdio.h>
#include <conio.h>
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();
}

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy