write a program to input a number and find the frequency of prime digits in it using c++ and also do the dryrun
Answers
Answer:
Examples:
Input: N = 12
Output: 1
Explanation:
Digits of the number – {1, 2}
But, only 2 is prime number.
Input: N = 1032
Output: 2
Explanation:
Digits of the number – {1, 0, 3, 2}
3 and 2 are prime number
Approach: The idea is to iterate through all the digits of the number and check whether the digit is a prime or not. Since there are only four possible prime numbers in the range [0, 9] and every digit for sure lies in this range, we only need to check the number of digits equal to either of the elements in the set {2, 3, 5, 7}.
Answer:
The details attached
Explanation:
#include <stdio.h>
#include <conio.h>
int main()
{
int n, i, flag = 0;
clrscr();
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=2; i<=n/2; ++i)
{
// condition for nonprime number
if(n%i==0)
{
flag=1;
break;
}
}
if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
getch();
return 0;
}