Write a program which promptsuser to enter an integer value. Using while loop print the valuesfromzero up to the number enteredby the user.

• Enlist the odd numbers out of them

• Enlist the prime numbers out of odd number list and printtheir sum (add all the prime numbers)

Answers

Answer 1
Answer:

Answer:Following is the c++ code for the problem:

#include <iostream>

using namespace std;

int main() {

   int number;

   cout<<"Enter the number"<<endl;

   cin>>number;

   int i=0,c=0,odd[500];

   while(i<=number)//loop for printing the numbers form 0 to number.

   {

       cout<<i<<" ";

       if(i%2!=0)// storing in the odd array if the number is odd.

       {

           odd[c++]=i;//storing odd numbers..

       }

       i++;

   }

   cout<<endl;

   i=0;

   cout<<"The odd numbers are "<<endl;

   while(i<c)//loop to print the odd numbers.

   {

       cout<<odd[i]<<" ";

       i++;

   }

   cout<<endl<<"The prime numbers are "<<endl;

   i=0;

   int sum=0;

   

   while(i<c)//loop to print the prime numbers..

   {

       int div=2;

       while(div<odd[i])

       {

           if(odd[i]%div==0)

           break;

           div++;

       }

       if(div==odd[i])

      {

           cout<<odd[i]<<" ";

           sum+=odd[i];//updating the sum..

      }

       i++;

   }

   cout<<endl<<"The sum of odd prime numbers is "<<sum<<endl;//printing the sum..

return 0;

}

Output :

Enter the number

49

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  

The odd numbers are  

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49  

The prime numbers are  

3 5 7 11 13 17 19 23 29 31 37 41 43 47  

The sum of odd prime numbers is 326.

Explanation:

First I have printed the values from 0 to n and i have taken an array to store odd numbers.After that i have printed the odd values.And after that i have printed prime numbers among the odd numbers and their sum.These all operations are done using while loop.


Related Questions

Which statement prints "hi" on the screen?(a) puts("hi");(b) put "hi";(c) puts "hi";(d) none of the above
What is the tool that is used to automatically search New information on the internet and organize if for future searches?
Which of the following terms is used to describe a program that copies itself repeatedly, using up resources and possibly shutting down the computer or network?(A) A virus(B) A warm(C) A trojan horse(D) A rootkit
A retail company assigns a $5000 store bonus if monthly sales are $100,000 or more. Additionally, if their sales exceed 125% or more of their monthly goal of $90,000, then all employees will receive a message stating that they will get a day off. When your pseudocode is complete, test the following monthly sales and ensure that the output matches the following. If your output is different, then review your decision statements.Monthly Sales Expected Output monthlySales 102500 You earneda $5000 bonus! monthlySales = 90000 monthlySales 112500 You earned a $5000 bonus! All employees get one day off!
Provide your own examples of the following using Python lists. Create your own examples. Do not copy them from another source. Nested lists The “*” operator List slices The “+=” operator A list filter A list operation that is legal but does the "wrong" thing, not what the programmer expects Provide the Python code and output for your program and all your examples.

Illustrator : how do you edit a swatch ?​

Answers

Answer:

To edit an existing pattern, double-click the pattern in the pattern swatch, or select an object containing the pattern and choose Object > Pattern > Edit Pattern

Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", and "pearl" that occur in String str. For example, if str has the value "the pear in the bowl", the code segments should both print "pear" and if str has the value "the pea and the pearl", the code segments should both print "pearl". Assume that str contains at least one instance of "pea".I.

if (str.indexOf("pea") >= 0)

{

System.out.println("pea");

}

else if (str.indexOf("pear") >= 0)

{

System.out.println("pear");

}

else if (str.indexOf("pearl") >= 0)

{

System.out.println("pearl");

}

II.

if (str.indexOf("pearl") >= 0)

{

System.out.println("pearl");

}

else if (str.indexOf("pear") >= 0)

{

System.out.println("pear");

}

else if (str.indexOf("pea") >= 0)

{

System.out.println("pea");

}

Which of the following best describes the output produced by code segment I and code segment II?

Both code segment I and code segment II produce correct output for all values of str.

Neither code segment I nor code segment II produce correct output for all values of str.

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pear" but not "pearl".

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pearl".

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".

Answers

Answer:

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".

Explanation:

The main issue with the first code segment is the way how the if else if condition are arranged. The "pea" is checked at the earliest time in the first code segment and therefore so long as there is the "pea" exist in the string (regardless there is pear or pearl exist in the string as well), the if condition will become true and display "pea" to terminal. This is the reason why the code segment 1 only work for the values of str that contain "pea".

Laptop components that can be replaced relatively easily include the ____ and the ____first part
screen
power supply
RAM

second part
hard disk
keyboard
touchpad​

Answers

Answer:

Power supply and Hard disk

Explanation:

Which of these is outside the scope of an art director's responsibility?

Answers

Answer:

Establishing Tight deadlines for a rush job.

Explanation:

The time taken for a rush job has nothing to do with the art director because it has nothing to do with art. Also rush jobs already call for tight deadlines so technically the deadline is already established.

Answer: cropping a photograph for the sake of space

Explanation: edge 22

Which statement is written correctly?

Answers

Answer:

B.

Explanation:

In Javascript, the if should have a condition attached to it with parenthesis and curly braces.

An 'array palindrome' is an array, which, when its elements are reversed, remains the same. Write a recursive function, isPalindrome, that accepts a tuple and returns whether the tuple is a palindrome. A tuple is a palindrome if: the tuple is empty or contains one element the first and last elements of the tuple are the same, and the rest of the tuple is a palindrome

Answers

Answer:

Following are the program in the Python Programming Language.

#define function

def isPalindrome(test):

#set the if condition to check tuple is empty

 if(len(test)==0):

   return True

#Check the tuple contain 1 element

 elif(len(test)==1):

   return True

#check the element of tuple is palindrome or not

 else:        

   lenth=len(test)

   #check first last element is equal or not

   if(test[0]==test[lenth-1] and isPalindrome(test[1:lenth-1] ) ):

   #then, return true

     return True

   #otherwise

   else:

   #Return False,

     return False

#define tuple type variable and initialize

test=(1,2,3,4,3,2,1)

#print and call the function

print(isPalindrome(test))

Output:

True

Explanation:

Here, we define a function "palindrome()" and pass an argument in its parameter, inside the function.

  • Set the if conditional statement to check the following tuple is empty or not if the tuple is empty then, it returns true.
  • Set the elif conditional statement to check the following tuple containing one element, then it returns True.
  • Otherwise, we set the length of the tuple in the variable "lenth".
  • Then, set if conditional statement to check the first and the last element of the tuple is the same then, returns true.
  • Otherwise, it return false.