Mar
23
#include<stdio.h>
#include<stdlib.h>
void main(){
int *ptr1;
int n,i,j,flg;
printf(“How many numbers you want to enter: “);
scanf(“%d”,&n);
ptr1=(int*) malloc(n*sizeof(int));
printf(“Enter %d numbers:\n”,n);
for(i=0;i<n;i++){
scanf(“%d”,(ptr1+i));
}
// to find the prime numbers
for(i=0;i<n;i++){
//*(ptr1+i);
flg=0;
for(j=2;j<*(ptr1+i);j++){
if(*(ptr1+i)%j==0){
flg=1;
break;
}
}
if(flg==0)
printf(“%d is a Prime Number\n”,*(ptr1+i));
}
free(ptr1);
}
Comments Off on Prime numbers using dynamic memory allocation in 1-D Array prog-5