Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This code found the prime number in array and replace it with '0'
- #include<stdio.h>
- #include<malloc.h>
- int isprime(int n)
- { int i,flag=0;
- for(i=2;i<=n/2;i++)
- { if(n%i==0)
- { flag++;
- break;
- }
- }
- if(flag==0 && n!=1)
- return 1;
- else
- return 0;
- }
- int main()
- {
- int *arr,i,j,n;
- printf("Enter number of elements:. ");
- scanf("%d",&n);
- arr= calloc(n,sizeof(int));
- //Enter all (distinct) elements of array/
- for(i=0;i<n;i++)
- { printf("Enter element %d: ",i+1);
- scanf("%d",&arr[i]);
- }
- printf("\n Here is the list:\n");
- for(i=0;i<n;i++)
- printf("%d ",arr[i]);
- for(i=0;i<n;i++)
- { if(isprime(arr[i])==1)
- arr[i]=0;
- }
- printf("\n List without prime number:\n");
- for(i=0;i<n;i++)
- printf("%d ",arr[i]);
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement