C Program to Find Prime Numbers in 10 number Array elements

27 Dec 2022 Balmiki Mandal 0 C Programming

Prime Number Finder in C

Introduction: Welcome to our online C program that helps you find and display prime numbers from a list of 10 input numbers. This simple tool is designed to make it easy for you to identify prime numbers within a set of values.

Instructions:

  1. Input Numbers: Enter 10 numbers in the input fields below. These numbers will be used to identify prime numbers.

  2. Find Primes: Click the "Find Primes" button to initiate the process of identifying prime numbers among the inputs.

  3. Result: The prime numbers found in the input list will be displayed in a separate array.

C Program Code for prime number within 10 numbers

#include 

// Function to check if a number is prime
int isPrime(int num) {
    if (num <= 1) return 0;
    for (int i = 2; i * i <= num; i++) {
        if (num % i == 0) return 0;
    }
    return 1;
}

int main() {
    int input[10];
    int primes[10];
    int primeCount = 0;

    // Input 10 numbers
    printf("Enter 10 numbers:\n");
    for (int i = 0; i < 10; i++) {
        scanf("%d", &input[i]);
    }

    // Find prime numbers and store them in the 'primes' array
    for (int i = 0; i < 10; i++) {
        if (isPrime(input[i])) {
            primes[primeCount] = input[i];
            primeCount++;
        }
    }

    // Display the prime numbers
    printf("Prime numbers in the list are: ");
    for (int i = 0; i < primeCount; i++) {
        printf("%d ", primes[i]);
    }
    printf("\n");

    return 0;
}

Note: This program uses the isPrime function to check if a number is prime. It then stores prime numbers in a separate array and displays the results.

Enter 10 numbers:
10 20 30 11 28 40 20 18 10 10
Prime numbers in the list are: 11

Conclusion:

Finding prime numbers among a set of input values has never been easier. Simply enter your numbers, click "Find Primes," and discover which numbers are prime. This tool is useful for various applications where prime numbers play a crucial role, such as cryptography and number theory. Enjoy exploring the prime numbers in your data!

Top Resources

Prime Numbers: C Program Example and Explanation

Design a function to check the given number is prime or not if prime return 1 else 0

Write a C Program to Check if a Number is Prime or Not Using For Loop

Writing a C Program to Print Prime Numbers Between 50 and 100

write a program to print prime numbers in 10 array elements.

Write a C program to input 10 numbers through the keyword and find the number of prime counts it stores the into a separate array and display it.

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.