# Untitled

unknown
plain_text
20 days ago
1.9 kB
1
Indexable
Never
```Question 3
#include<stdio.h>
#include<stdbool.h>

int isPrime(int n)   // this function will calculate the prime
{
for (int i = 2; i < n; i++)
{
if (n % i == 0)
{
return false;   // it is for not prime
}

}
return true;  // it is for prime

}

{
for (int i = 0; i < 5; i++)
{
if (isPrime(arr[i]))   // in isprime it will call and give the prime number if number is prime it will execute
{
int sum = 0;
int finalResult = 0;
int n = arr[i];
while (n > 0)  // if array integer is greater than 0 it will give the sum and the difference
{
int rem = n % 10;
n = n / 10;
sum = sum + rem;
}
finalResult = arr[i] - sum;
arr[i] = finalResult;  /// final value again stored in array
printf("%d ", arr[i]);
}
else   // else condition will reverse the non prime number
{
int p = arr[i];
int sumofReverse = 0;

while (p > 0)   // while loop will give the reverse value
{
int remainder = p % 10;
sumofReverse = sumofReverse * 10 + remainder;
p = p / 10;
}
arr[i] =  sumofReverse;  // reverse value again stored in the array
printf("%d ", arr[i]);
}
}

}

int main()
{
int arr[5];
printf("Enter the Array elements: ");
for (int i = 0; i < 5; i++)   // enter the 5 array elements
{
scanf("%d", &arr[i]);
if(arr[i] <= 0 || arr[i] > 999)
{
printf("Invalid input\n");
return 0;
}

}