1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olga2289 [7]
3 years ago
10

-Write a function is_perfect, which accepts a single integer as input. If the input is not positive, the function should return

a string "Invalid input." If the input is positive, the function should return True if the input is a perfect number and False otherwise.
Computers and Technology
1 answer:
Genrish500 [490]3 years ago
4 0

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// function

string is_perfect(int n)

{

   // string variables

   string str;

   // if number is negative

   if (n < 0)

   {

        str="invalid input.";

   }

   // if number is positive

   else

   {

      int a=sqrt(n);

      // if number is perfect square

      if((a*a)==n)

      {

          str="True";

      }

      // if number is not perfect square

      else

      {

          str="False";

      }

   }

   // return the string

     return str;

}

// main function

int main()

{

   // variables

int n;

cout<<"enter the number:";

// read the value of n

cin>>n;

// call the function

string value=is_perfect(n);

// print the result

cout<<value<<endl;

return 0;

}

Explanation:

Read a number from user and assign it to variable "n".Then call the function is_perfect() with parameter n.First check whether number is negative or not. If number is negative then return a string "invalid input".If number is positive and perfect square then return a string "True" else return a string "False".

Output:

enter the number:-3

invalid input.

enter the number:5

False

enter the number:16

True

You might be interested in
You run the ipconfig command on your computer, and it reports an IP address of 169.254.75.10 on the Ethernet interface. Which de
Ray Of Light [21]

Answer:

This IP address is assigned to the interface by the following device:

d. The local computer

Explanation:

  • Ipconfig command is also known as Internet protocol configuration command. It is command line tool that is used to configure the IP of network connections. This command give us information about the information about IP and other parameters like default gateways.
  • The IP address 169.254.X.X is such IP address that can have values from 169.254.0.1 to 169.254.254.
  • 169.254.X.X is a Automatic Private IP Address that tells that our computer is not connected with the internet because the computer is not getting IP address from server.
5 0
4 years ago
Помогите пожалуйста исправить код и ответить на вопрос задачи. Что покажет этот код? PYTHON s = ‘Hi! Mister Robert' i = 0 while
babymother [125]

Answer:

It checks if "?" exists in the string s. print Найдено if found, otherwise prints Готово

Explanation:

s = ‘Hi! Mister Robert'  

i = 0  

while (i < (len(s))) and (count==0):  

   if s[i] == ‘?':  

       count+=1  

       i+=1

if count > 0:  

   print("Найдено")  

else:  

   print ("Готово")

7 0
4 years ago
What are the steps to create a new folder named C12000 and save it
MrRa [10]
You would go to downloads in your library then click new folder, name it, save it, then drag it there you need it
3 0
3 years ago
What transport layer protocol does DNS normally use?
saveliy_v [14]

Explanation:

DNS uses the User Datagram Protocol (UDP) on port 53 to serve DNS queries. UDP is preferred because it is fast and has low overhead. A DNS query is a single UDP request from the DNS client followed by a single UDP reply from the server.

3 0
3 years ago
Web beacons are tiny, invisible software programs hidden in email messages and web pages that are used to track and report a use
Umnica [9.8K]

Answer:

The answer is "True".

Explanation:

The web beacons are one of the different techniques, that are used on web pages and emails, to check whether a user has access to some unobtrusively. It is a line, that is often invisible, and typically does not exceed 1 pixel.

  • It is usually used with cookies.
  • It is also known as a small graph, which generates a request to the server for tracking service.
7 0
3 years ago
Other questions:
  • Every preprocessing directive must begin with:
    11·1 answer
  • Technician A says one disadvantage of fiber optic cables is that they are more expensive and very heavy. Technician B says one d
    6·1 answer
  • Why should the ISO be adjusted when taking a picture of a child blowing out candles in a darkened room?
    10·1 answer
  • Marilyn needs help exporting her spreadsheet as a few different types of files. She needs to know exactly how her file should be
    11·1 answer
  • A database design where certain data entities are combined, summary totals are carried in the data records rather than calculate
    5·1 answer
  • For this lab you will write a class to create a user-defined type called Shapes to represent different shapes, their perimeters
    6·1 answer
  • 5.2
    8·1 answer
  • Your manager has requested you keep a timesheet showing how many hours you work each day and what projects you work on during th
    13·2 answers
  • Which statement about routers is !!!FALSE!!!
    10·1 answer
  • What is a reason for zipping a file?A. to encrypt themB. to return them to their original sizeC. so they display properly on a W
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!