Computer Science, asked by adilbinaziz17, 2 months ago

write an algorithm which asks for length of the side of a square validate it to see that it is a value between 1 and 100 and then calculate and display its perimeter otherwise give ERROR message

Answers

Answered by rajSamDKA
0

Answer:

  1. start
  2. declar value length
  3. take user input
  4. put user input in length value
  5. check if length is between 1 and 100
  6. display error if statement is false
  7. stop if statement is false
  8. continue if statement is true
  9. display 4 x length as parameter
  10. stop

Explanation:

The algorithm can be written in different programming languages.

python3 algorithm for finding perimeter of square-

# taking user input

length=float(input("Enter the length of the side of your square: "))

# checking number

if length>=1 and length<=100:

# printing output

print("Perimeter of your square is "+str(4*length))

else:

print("ERROR: please enter valid value between 1 and 100")

c++ algorithm for finding perimeter of square-

#include <iostream>

using namespace std;

int main(){

// defining veriable length

double lenght;

// asking user for input

cout<<"Enter the length of the side of your square: ";

// taking user input

cin>>lenght;

// checking number

if (lenght>=1 and lenght<=100)

{

 // giving output

 cout<<"Perimeter of your square is "<<4*lenght<<endl;

}else{

 cout<<"ERROR: please enter valid value between 1 and 100"<<endl;

};

}

program output:

$python3 algorithm.py            

Enter the length of the side of your square: 76.35

Perimeter of your square is 305.4

$g++ algorithm.c++ -o exe && ./exe

Enter the length of the side of your square: 46.47

Perimeter of your square is 185.88

$python3 algorithm.py            

Enter the length of the side of your square: 200

ERROR: please enter valid value between 1 and 100

$./exe                            

Enter the length of the side of your square: 345

ERROR: please enter valid value between 1 and 100

Similar questions