answer.
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
AysviL [449]
2 years ago
15

Assume the availability of a function is_prime. Assume a variable n has been associated with positive integer. Write the stateme

nts needed to find out how many prime numbers (starting with 2 and going in increasing order with successively higher primes [2,3,5,7,11,13,...]) can be added before exceeding n. Associate this number with the variable k.
Computers and Technology
1 answer:
vivado [14]2 years ago
6 0

Answer:

def main():

   n = int(input('Enter the value of the variable n:'))

   k=2;

   totalSum = 0

   print('The list of the prime numbers are as follows:')

   while k <= n:

       totalSum = totalSum+is_prime(k)

       k=k+1

   print('Total sum of the prime numbers:',totalSum)

def is_prime(k):

   primeNumber = 0      

   i=1

   while i<=int(k):

       if (k % i) == 0:

           primeNumber = primeNumber + 1

       i=i+1

   if(primeNumber==2):      

       print(k)

       return k;

   else:        

       return 0;

main()

Explanation:

  • Run the while loop until k is less than n.
  • Determine if the variable k is prime then add it to the totalSum variable.
  • Increment the value of k by 1.
  • Create a function isPrime to check whether the number is prime  or not by determining the factors of k which can be found using the modulus operator.
  • Call the main function at the end.

You might be interested in
A computer never gets tired or bored while working for a long time .. ​
Angelina_Jolie [31]

Answer :Computers never get tired or bored because of doing the same task continuously. They work in the same manner all the time. A computer can store large amount of information in its memory.

Explanation: it is quality which makes the user to be dependent on computer. As we all know, computer systems do repetitive tasks without any boredom, tiredness, or fatigue.

5 0
2 years ago
Write a while loop that prints usernum divided by 2 until user_num is less than 1. The value of user_num changes inside of the l
zaharov [31]

Answer:

The program to this question can be describes as follows:

Program:

#include <iostream> //defining header file

using namespace std;

int main() //defining main method

{

float user_num ;//defining float variable

cout<<"Enter any number: "; //message

cin>>user_num; //input value from the user

while (user_num >= 1) //defining loop to calculate value

{

user_num =user_num/ 2; //diving the value

cout<<user_num<<endl; //print value

}

return 0;

}

Output:

Enter any number: 20

10

5

2.5

1.25

0.625

Explanation:

In the above program, a float variable user_num is declared in which we store input value from the user end, in the next step, a while loop is declared, which calculates, the given value.

  • In the loop a condition is defined, that user_num value is greater than equal to 1, inside the loop it will divide the value of the user_num and store in this variable.
  • In this print, the method is used, which prints its variable values.
5 0
2 years ago
C++ :Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the outpu
yaroslaw [1]

Answer:

#include <iostream>

#include <cstdlib>

using namespace std;

int t;

char HeadsOrTails(){

char a='h';

char b='t';

if(t%2==0)

return a;

else

return b;

}

int main ()

{

 int n,  c, b;

   

 cout << "Enter the number of decisions you want" << endl;

 cin >> n;

 b=1;

 cout << "Decisions are:" << endl;

  srand(100);

 for (c = 1; c <= n; c++)

 {

   

   t = rand();

   if(HeadsOrTails()=='h'){

    cout<<b<<".heads"<<endl;

    b++;

   }

   else{

    cout<<b<<".tails"<<endl;

    b++;

   }

   

 }

 return 0;

}

Explanation:

random number generator is used to generate a number and then heads and tails is decided on even and odd number basis. if number is even then decision is head and if number is odd then decision in tails

3 0
2 years ago
To gain experience of using and combing different sorting algorithms: election sort, insertion sort, merge sort, and quick sort.
ch4aika [34]

Answer:

Motivation? The search problem.

Sorting algorithms: insertion sort, shellsort, heapsort, mergesort, quicksort, bubblesort

At the very least, "general purpose" sorting algorithms require O(n log n) comparisons

Explanation:

3 0
2 years ago
If you were investigating login issues on a Windows computer, which portion of the Event Viewer logs would be a good place to st
USPshnik [31]

Answer:

If we are investigating login issues then we have to start with 'security logs' in 'windows logs' portion of Event viewer.

Explanation:

Much information about login issues is contained in log files which are related to security because it is mostly security issue. Some it is also better to start with 'system logs' portion of windows logs portion of Event viewer when there may be system problems instead of security issues. But in most cases there is security issues so 'security logs' is better option overall

6 0
2 years ago
Other questions:
  • A telephone-repair technician uses a meter to measure voltage on a phone line. This meter is an example of _____. hardware softw
    10·2 answers
  • What tool extends the basic functionality provided in task manager with additional features and tools?
    8·1 answer
  • Which process is used to protect transmitted data in a vpn?
    12·1 answer
  • Edria was faced with a situation in which she was given sensitive information about twenty different clients, including their so
    13·2 answers
  • [20 POINTS] Jaime has to configure the dmz network of his organization to the optimum level. Which is the best practice to do so
    7·2 answers
  • 3.5 Code Practice
    11·2 answers
  • 1. Show that the three security services-confidentiality, integrity, and availabilty- are sufficient to deal with the threats of
    10·1 answer
  • Use the following data definitions data myBytes BYTE 10h,20h,30h,40h myWords WORD 3 DUP(?),2000h myString BYTE "ABCDE" What will
    9·1 answer
  • Write a function called st_dev. St_dev should have one #parameter, a filename. The file will contain one integer on #each line.
    7·1 answer
  • How does the discussion of “Luddites,” “Marx,” and “John Maynard Keynes” in paragraph 21 contribute to the development of the id
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!