Search
 
SCRIPT & CODE EXAMPLE
 

C

what are prime numbers

Prime numbers: whole numbers greater than 1 that are only divisible 
by 1 and itself.
Comment

prime numbers

A number only divisible by 1 and itself
Comment

prime numbers

#include <iostream>
#include <cmath>
#include <iostream>

#define el "
"

using namespace std;

bool isprime(int n)
{
    if (n <= 1)
    {
        return 0;
    }
 
    for(int i=2 ; i <= sqrt(n); i++) // [sqrt(n)] is faster in calculations than [n/2]
    {
        if(n%i == 0)
        {
            return 0;
        }
    }
    return 1;
};

int main() 
{
    long long num;

    cin >> num; // ~~~ Enter a number
 
    (isprime(num))? cout << "The number (" << num <<") is a prime" << el : cout << "The number (" << num <<") isn't a prime" << el;
        
    return 0;
}
Comment

what is prime number

Number which is only divisible by itself and 1(eg. 2,3...)
Comment

Prime Numbers

using System;
public class Program
{
    static void Main(string[] args)
    {
        var results = GenerateSieve(1000);
        var i=0;
        foreach (var item in results)
        {
            if(item) Console.Write(i + " ");
            i++;
        }
    }
 
    static bool[] GenerateSieve(int num)
    {
        // Creating an array indicating whether numbers are prime.
        bool[] isPrime = new bool[num + 1];
        for (int i = 2; i <= num; i++) isPrime[i] = true;
 
        // Removing out multiples.
        for (int i = 2; i <= num; i++)
        {
            // Check if i is prime.
            if (isPrime[i])
            {
                // Eliminate multiples of i.
                for (int j = i * 2; j <= num; j += i)
                    isPrime[j] = false;
            }
        }
        return isPrime;
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: stack and heap memorym in ram 
C :: tuples in c 
C :: Relational Operator in C language 
C :: snprintf c 
C :: int to void* c 
C :: ternary operator in c 
C :: %g and %e in c 
C :: majuscule en c 
C :: declaration of string in c 
C :: sphinx-doc 
C :: C Syntax of struct 
C :: deleting a word with copy fuction c code 
C :: 2 html 1 javascript 
C :: largest value in u64 
C :: spacemacs start server 
C :: router solicitation and advertisement magic is used by 
C :: permutation and combination program in c 
C :: reset c array to zero 
C :: c timespec 
C :: false and true in c 
C :: man write c 
C :: Integer Output 
C :: WARNING: QA Issue: rdepends on 
C :: c language dictionary implemet 
C :: return multiple values using the call by reference 
C :: lmkmaksmxkmakkxxamkskaamkamkaxsmkasm 
C :: c input is skipped 
C :: memset c 
C :: c make list 
Dart :: flutter delay 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =