Answer to Question #296659 in C++ for Anil Rathore

Question #296659

Take input of your registration number in the University. Write a programme to print all the



prime numbers digits in your registration number.

1
Expert's answer
2022-02-11T10:19:46-0500
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>


#define PRIME 45
#define NOT_PRIME 44


int is_prime( int value);


int main()
{
	unsigned long int code=0;
    printf("Enter code : ");
    scanf("%lu", &code);
    char str[50];
    _ultoa(code, str, 10);
    printf("Values : ");
    for (int i = 0; i < strlen(str); i++)
    {
        if (is_prime((int)((int)(str[i]) - '0')) == PRIME)
        {
            printf("%c\t", (str[i]));
        }
    }


	getc(stdin);
	return 0;
}


int is_prime( int value)
{
    int flag = PRIME;
    for (int i = 2; i <= value / 2; i++) {
        if (value % i == 0) {
            flag = NOT_PRIME;
            break;
        }
    }
    return flag;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog