#include <stdio.h>
#include <stdlib.h>
int isPrime(int num)
{
int i;
int flag=0;
// 1 is not prime nor composite
if(num==1)
return 0;
for(i=2; i<num; i++)
{
if(num%i ==0)
{
flag =1;
break;
}
}
//flag is 1, if number is not prime
if(flag==1)
return 0;
else
return 1;
}
int main()
{
int* ptr;
char *cptr;
int n=10, i;
// Dynamically allocate memory using malloc()
ptr = (int*)malloc(n * sizeof(int));
cptr = (char*)malloc(n * sizeof(char));
// Check if the memory has been successfully
if (ptr == NULL) {
printf("Error Memory not allocated.\n");
exit(0);
}
else
{
for (i = 0; i < n; i++)
{
printf("Enter %d element:",i+1);
scanf("%d",&ptr[i]);
}
for(i=0;i<n;i++)
{
if(isPrime(ptr[i]))
cptr[i]='P';
else if(ptr[i]%2==0)
cptr[i]='E';
else
cptr[i]='N';
}
printf("The elements of the array are: ");
for (i = 0; i < n; ++i)
{
printf("%c, ", cptr[i]);
}
}
return 0;
}
Comments
Leave a comment