//Header Files
#include <iostream>; //Required for i/o
#include <iomanip>; //Required for i/o Manipulators
#include <conio.h>; //Required for clrscr (Clear Screen)
#include <dos.h>; //Required for DOS commands
#include <stdio.h>; //
#include <math.h>; //Required for Math Library Functions
#include <ctype.h>; /*Required for Character
Analization Library Functions*/
using namespace std;
/*Programmer: Ty Meador
Name: Project 9-2
Purpose: Calculate the Square root of a number as
a Multiplier and a Square root
Function Prototypes*/
void calceve(int incoming_integer);
//Globals
//double PI = 3.1415926535897
main()
{
system("cls");
int integer = 0;
while(integer < 1)
{
cout<<"Please Input a Positive Integer: ";
cin>>integer;
if(integer > (32766))
{
system("cls");
cout<<"Number Too Large\n";
integer = 0;
}
}
calceve(integer); //Passes input to function calc(int);
cout<<'\n';
system("pause");
return 0;
}
void calceve(int incoming_integer)
{
double root = sqrt(incoming_integer), multiplier = 0;
int i = 0,i2; //i is outer loop control, i2 is inner
int report = 2;
do // this loop checks to see if the number is a perfect square, if so
{ // theres no reason to execute the next loop
i++;
if(i == root)
{
i = root;
i2 = 1;
report = 1;
break;
}
}while(i < root);
if (report == 2)//this checks to see if the previous loop determined
{ //the number to be a perfect square, if not, GO!;
i = 0; //used 'i' as loop control for last loop, had to reset;
do//outer loop runs until control multiplier == root;
{
i++;
i2=0;
if (i > incoming_integer)//if the outer loop becomes larger than
{ //the number input, the number cannot
i = 1; //be simplified, so break loop, and set
i2 = incoming_integer;//variables for proper output
report=0;
break;
}
while(i2 < incoming_integer-1)//inner loop runs to 1 less
{ //than input, to keep all answers from
i2++; //being "1 * sqrt(input)"
multiplier = i * sqrt(i2);
if((multiplier >= root))//if multiplier >= root, break inner loop
{ //because they cannot be equal
break;
}
}
}while(multiplier != root);
}
cout<<endl<<incoming_integer<<" = "<<i<<" * sqrt("<<i2<<')';
if(!report)
{
cout<<" OR "<<sqrt(incoming_integer);
cout<<"\n\n(Cannot Be Simplified to a\nSquareroot and Multiplier)\n";
}
}
Attached File(s)
-
Anomalie.bmp (712.2K)
Number of downloads: 37

New Topic/Question
Reply




MultiQuote







|