PROBLEM SOLVING THROUGH PROGRAMMING IN C.
By Prof. ANUPAM BASU
WEEK 8:PROGRAM 5:
Write a program to express a given integer as a Sum of Two Prime Numbers
For example if the number is 10The result will be
10 = 3 + 7
10 = 5 + 5int i,flag=0; for (i = 2; i <= n / 2; ++i) { if (checkPrime(i) == 1) { if (checkPrime(n - i) == 1) { printf("%d = %d + %d\n", n, i, n - i); flag = 1; } } } if (flag == 0) printf("%d cannot be expressed as the sum of two prime numbers.", n); return 0; } int checkPrime(int n) { int i, isPrime = 1; for (i = 2; i <= n / 2; ++i) { if (n % i == 0) { isPrime = 0; break; } } return isPrime; }
CLICK ON BELOW LINK.
<<CLICK HERE FOR WEEK 9 :PROGRAM -01>>
<<CLICK HERE FOR WEEK 9 :PROGRAM-02>> FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
No comments:
Post a Comment
If you have any problems related to solutions or any concept please let me know.