Skip to content

MyUstaadG

Learn to Serve

  • Computer Science
    • Software
    • Computer Tips
    • Coding
      • Conditional Structures Exercises
      • Loops Exercises
      • Arrays Exercises
      • Python Exercises
    • Microsoft Office
      • MS Excel
      • MS Word
  • Videos
    • Funny Videos
    • Health and Fitness Videos
    • PUBG Videos
    • Technology Videos
  • News
  • Funny
  • Memes
  • Playwright Tutorials
  • Tutorials
  • Toggle search form

Write a program that inputs fifteen integer values in an array. It finds out all the prime numbers.

Posted on October 15, 2021 By myustaadg.com
Spread the love

Write a program that inputs fifteen integer values in an array. It finds out all the prime numbers stored in an array and displays the result on screen.

So let’s Write Code:

Introduction to C++ Programming | Download and Install Dev C++ Compiler

Let’s build logic First:

Algorithm for code:

  • Step 1: Start
  • Step 2: Declare an array and variables n, count, d and p
  • Step 3: Initialize variable count = 0, p=1, d=2;
  • Step 4: Input Numbers from User.
  • Step 5: if(arr[n]%d==0 ) set p=0 and break.
  • Step 6: if remainder is 1 then Count ++.
  • Step 7: Print Prime Numbers
  • Step 8: Stop

Write a program that inputs fifteen integer values in an array. It finds out all the prime numbers.

#include<iostream>
using namespace std;
main()
{
int arr[15], n, count = 0, d, p;
for(n = 0;n<=14; n++)
{
cout<<"Enter a value in element "<<n<< " of the array ? ";
cin>>arr[n];
}
for(n = 0;n<=14; n++)
{
p = 1;
for(d = 2; d < arr[n]; d++)
if (arr[n]%d ==0)
{
p = 0;
break;
}
if (p == 1)
{
cout<<arr[n]<<endl;
count++;
}
}
cout<<"\n Prime numbers stored in an array are:"<<count;
}

Hope You will learn Something. Happy Coding.

Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4

Click on the below Links for more Programming Exercises:

Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/

Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/

Arrays Exercises, Programming Exercises Tags:Array Exercises, Array exercises in C++, array in Object oriented programming, array in OOP, Arrays in C++, C++ programming tutorial, count number of primes in an array, count number of primes in an array in c++, how do you fing prime numbers in an array?, how do you separate prime numbers from an array of numbers?, how to find prime number in an array in C, how to find prime number in an array in C++, how to find prime number in an array in oop, how to store prime number in an array in C++, how to store prime number in an array in object oriented programming, how to store prime number in an array in oop, prime numbers in an array in c++, prime numbers in an array in oop, store prime numbers in array and display, what is algorithm for prime numbers?, what is the best algorithm for finding a prime number, Write a program that inputs fifteen integer values in an array. It finds out all the prime numbers., Write a program that inputs integer values in an array. It finds out all the prime numbers.

Post navigation

Previous Post: Write a program that inputs ten values in an array and calculates the sum of these values.
Next Post: Write a program that inputs ten values into an array. It finds out the average value of the array

More Related Articles

Write a program that inputs data into a string and searches the ‘vowel’ characters from the string and displays on the screen. Arrays Exercises
Write a program that initializes an array with the number of days of different months. It inputs the number of month and displays the number of days of the entered month. Arrays Exercises
Write a program that inputs temperatures for seven days of the week into a one-dimensional array “temp”. Arrays Exercises
Write a Program to Build a Simple Calculator in C++ Write a Program to Make a Simple Calculator in C++ Programming Language | Solved Programming Exercises Programming Exercises
Write a program that input two integers and display Quotient and remainder on the screen | Python Programming Programming Exercises
Write a program that sorts one-dimensional array’s values into descending order using the bubble sort method. Arrays Exercises

Copyright © 2022 MyUstaadG.

Powered by PressBook Blog WordPress theme