"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Sunday, 19 April 2020

Prime Number Program In C / C++

Prime Number Program In C / C++

     A whole Number which is greater than 1 and which is divider of itself. For example 13 divided only 13,17 divided only 17 and series is 2,3,5,7,11,13,17, ...

Prime Code in C

#include<stdio.h>
#include<conio.h>

int main(){
int num,i,j;
int temp=0;
printf(" Enter Any integer Number ");
scanf("%d",&num);
if(num<2){
printf(" Number Should be greater than 1 \n");
}
else{
for(i=2;i<=num;i++){
for(j=2;j<i;j++){
if(i%j==0){
temp=1;
}
}
if(temp==0){
printf("\n %d",i);
}
else{
temp=0;
}
}
}
return 0;

}


Prime Number Code in C++

#include<iostream>
using namespace std;

int main(){
int num,i,j;
int temp=0;
cout<<" Enter Any integer Number ";
cin>>num;
if(num<2){
cout<<" Number Should be greater than 1 \n";
}
else{
for(i=2;i<=num;i++){
for(j=2;j<i;j++){
if(i%j==0){
temp=1;
}
}
if(temp==0){
cout<<"\n"<<i;
}
else{
temp=0;
}
}
}
return 0;

}

No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.