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
What data type or you use to represent true or false values?
vfiekz [6]
The Boolean type is used to represent true or false values
3 0
3 years ago
Plz answer me will mark as brainliest ​
victus00 [196]

Answer:

Application

Explanation:

Application software comes in many forms like apps, and even on computers. The software is most common on computers of all kinds while mobile applications are most common on cellular devices.

3 0
3 years ago
Read 2 more answers
Suppose there are two ISPs providing WiFi service in a café. Each ISP operates its own AP and has its own IP address block. If b
Alinara [238K]

Answer:

As a design rule, access points within range of each other should be set to channel frequencies with minimal signal overlap. Users will find that roaming doesn’t work well, and performance will degrade because of interference between access points.

Explanation:

8 0
4 years ago
2. A host computer with an IP address of 172.16.29.155 using a subnet mask of 255.255.255.0 and a gateway of 172.16.29.1 pings a
ASHA 777 [7]

Answer:

From the host IP address and subnet mask, you can tell that both computers are on the same network. Host 172.16.29.155 will need to send an ARP request broadcast for 172.16.29.83 to get the MAC address and update its ARP table if the host 172.16.29.83 has not already done so.

Explanation:

<h2>ADDRESS RESOLUTION PROTOCOL (ARP)</h2>

Address Resolution Protocol (ARP) is a procedure for mapping a logical address known as the IP address to a physical address known as MAC (Media Access Control) address in a local area network. The job of the ARP is essentially to translate 32-bit addresses to 48-bit addresses and vice-versa when using IP Version 4 (IPv4) to communicate on the network.

Most of the computer programs/applications use logical address (IP address) to send/receive messages, however, the actual communication happens over the physical address (MAC address) this happens in the layer 2 of the OSI model. An ARP request is a broadcast, and an ARP response is a Unicast.

Scenarios when ARP is used:

Scenario-1: The sender is a host and wants to send a packet to another host on the same network.

·        Use ARP to find another host’s physical address

Scenario -2: The sender is a host and wants to send a packet to another host on another network.

·        Sender looks at its routing table.

·        Find the IP address of the next-hop (router) for this destination.

·        Use ARP to find the router’s physical address

Scenario -3: the sender is a router and received a datagram destined for a host on another network.

·        Router checks its routing table.

·        Find the IP address of the next router.

·        Use ARP to find the next router’s physical address.

Scenario -4: The sender is a router that has received a datagram destined for a host in the same network.

·        Use ARP to find this host’s physical address.

The situation in the question above falls under scenario-1. From the host IP address and subnet mask, you can tell that both computers are on the same network. Host 172.16.29.155 will need to send an ARP request broadcast for 172.16.29.83 so to get the MAC address and update its ARP table if the host 172.16.29.83 has not already done so.

7 0
4 years ago
A(n) __________ is a common list operation used in programming. its purpose is to iterate through a list of items, one item at a
Nataliya [291]
I would say C- Priority List.
I hope this helps! :)
5 0
3 years ago
Other questions:
  • 2. Identify the diagram and define it.<br>13. What are pollen grains ?<br>4. What is an embryo?​
    12·1 answer
  • An iPad Is An Example Of Which Type Of Computer?
    11·2 answers
  • Consider the following methods:
    5·1 answer
  • As the demand for goods and services increases, job growth _____. a. increases b. decreases c. remains the same d. none of the a
    15·2 answers
  • Sometimes, fourth-generation languages (4GLs) are called procedural languages
    9·1 answer
  • (10 points) 5.12. Discuss how the following pairs of scheduling criteria conflict in certain settings. a. CPU utilization (effic
    9·1 answer
  • Describe how a web browser and web server work together to send a web page to a user
    8·1 answer
  • Write a program second.cpp that takes in a sequence of integers, and prints the second largest number and the second smallest nu
    7·1 answer
  • How to connect apple pencil 2 to ipad 8th generation?
    11·1 answer
  • QUESTION 5
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!