prime numbers in c
#include<stdio.h> main() { int n, i, count=0; printf("Enter Number"); scanf("%d",&n); for ( i = 1; i<= n; i++) { if (n % i == 1) { count++; } } if( count == 2) { printf("Prime Number"); } else { printf("Not A Prime Number"); } }
prime numbers in c
#include<stdio.h> main() { int n, i, count=0; printf("Enter Number"); scanf("%d",&n); for ( i = 1; i<= n; i++) { if (n % i == 1) { count++; } } if( count == 2) { printf("Prime Number"); } else { printf("Not A Prime Number"); } }
prime no program in c
#include<stdio.h> int main() { int n,i; printf(“\nEnter the number : “); scanf(“%d”,&n); for(i = 2; i <= n/2; i++) { if(n % i ==0) { break; } } if(i > n/2) printf(“\n%d is a Prime Number\n”,n); else printf(“\n%d is not a Prime Number\n”, n); return 0; }
program to know if a number is prime
#include<bits/stdc++.h> using namespace std; bool Is_Prime(long long x){ if(x%2==0)return false; for(int i=3;i*i<=x;i+=2) if(x%i==0)return false; return true; } int main(){ long long x; cin>>x; if(Is_Prime(x))cout<<"Is Prime"; else cout<<"Is not Prime"; }
prime number c
#include <stdio.h> int main() { int i, num, p = 0; printf("Please enter a number: \n"); scanf("%d", &num); for(i=1; i<=num; i++) { if(num%i==0) { p++; } } if(p==2) { printf("Entered number is %d "\ "and it is a prime number.",num); } else { printf("Entered number is %d "\ "and it is not a prime number.",num); } }
prime number c program
int isPrime(int n) { for (int i = 2; i < n; i++) if (n % i == 0) return 0; return 1; }
c program to check prime number
//program to find prime number or not using c programming #include<stdio.h> #include<conio.h> // program starts from here after main() function void main(){ int n; int i,count =0; // count is incremented when the loop is true. printf("Enter the number\n"); scanf("%d",&n); for (i=1; i<=n; i++){ if(n%i==0){ count++; } } // for the prime number the no of count is 2 // number is divided by 1 or itself(given number) so count ==2 if(count ==2){ printf("%d is prime number.\n",n); } // for the composite number the number is divided by more than 2 number. else{ printf("%d is not prime number\n",n); } getch(); }
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us