#include<stdio.h> #include<stdlib.h> int count_sum = 0; int count_product = 0; int check_sum_prime(int num); int check_product_prime(int num); int check_digit(int num); int check_sum_prime(int num) { int rem=0; int mult = 0; int final = 0; while(num!=0) { rem=num%10; mult+=rem; num=num/10; } if(check_digit(mult) != 1) { check_sum_prime(mult); } else if(check_digit(mult) == 1) { if(mult==2 || mult==3 || mult==5 || mult==7 ) { count_sum++; } } } int check_product_prime(int num) { int rem=0; int mult = 1; int final = 0; while(num!=0) { rem=num%10; mult*=rem; num=num/10; } if(check_digit(mult) != 1) { check_product_prime(mult); } else if(check_digit(mult) == 1) { if(mult==2 || mult==3 || mult==5 || mult==7 ) count_product++; } } int check_digit(int num) { int count=0,rem1; while(num!=0) { rem1=num%10; count++; num/=10; } return count; } main() { do { int choice; int i; int upper_limit,lower_limit; printf("\n\n********** MENU **********\n"); printf("\n1. Check Product Prime."); printf("\n2. Check Sum Prime."); printf("\n3. EXIT."); printf("\nEnter Your Choice:"); scanf("%d",&choice); switch(choice) { case 1: count_product = 0; printf("\n********** Check Product Prime **********\n\n"); printf("Enter the Range:-----"); printf("\n\nLower Limit: "); scanf("%d",&lower_limit); printf("\nUpper Limit: "); scanf("%d",&upper_limit); for(i=lower_limit;i<=upper_limit;i++) check_product_prime(i); printf("\nNumber of Sum Primes between %d and %d = %d",lower_limit,upper_limit,count_product); break; case 2: count_sum = 0; printf("\n********** Check Sum Prime **********\n\n"); printf("Enter the Range:-----"); printf("\n\nLower Limit: "); scanf("%d",&lower_limit); printf("\nUpper Limit: "); scanf("%d",&upper_limit); for(i=lower_limit;i<=upper_limit;i++) check_sum_prime(i); printf("\nNumber of Sum Primes between %d and %d = %d",lower_limit,upper_limit,count_sum); break; case 3: printf("\nThanks Friend for checking my code....\n"); exit(0); default: printf("\nPlease give a valid choice\n"); } } while(1); }
C Prime Check Product or Sum
Post A Comment:
0 comments: