We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>


Looking For Something at vustudents.ning.com? Click Here to Search

Assignment Question :

You are required to write a program in C# programming language which will get a numeric value from user and show two prime numbers whose addition is equal to the number entered by user. You need to show all combination of prime numbers.

 

Assignment Instructions:

  • Find two prime numbers whose addition will be equal to user entered number.
  • Find all possible combinations of prime number whose addition will be equal to number entered by user. 

Hints:

To make the solution easily first you need to understand the problem with an example.

  • Suppose user entered the number 36. So you have N = 36.
  • Iterate from 2 to N/2 and find a prime number. Subtract the prime number from 36, if remaining is also prime number then you found two prime numbers whose sum is equal to user’s entered number. You can see its working in Sample Output video.
  • isPrime(n) method you created in Assignment no. 3 will help you to check a number is prime or not. Just you need to change it from Java to C# syntax.

Sample Output:

For sample output watch Sample Output video file.

 

Assignment Submission Instructions:

If you do not have Microsoft Visual Studio to make program in C# then use online tool given on http://volatileread.com/UtilityLibrary/SnippetCompiler

The procedure to use online tool is showing in Sample Output video file.

Please note that due date of assignment will not extend, so do not wait for last date and submit your solution as quickly as possible.

Due Date: Tuesday, February 06, 2017.

Share This With Friends......

+ Click Here To Join also Our facebook study Group.

This Content Originally Published by a member of VU Students.

+ Prohibited Content On Site + Report a violation + Report an Issue


..How to Join Subject Study Groups & Get Helping Material?..


Views: 2403

See Your Saved Posts Timeline

Replies to This Discussion

Share Solution dosto

Thank God i have done....

Attachments:

Thank u so much Malik Sohail..

Malik bhai aap ke code main aik error hai

video main 31 dene se us ka answer 2+29 ata hai lakin aap ka to usy exoress hi ni krta......... main ne pic lagayi hai dekh ly

Attachments:

1 wala vu wali video ki pic hai 2 wali aap ka code run kiya hai..
is ka solve ker de

just change i=3 with i=2 in for loop in this portion

Console.Write("Input a positive integer: ");
n = Convert.ToInt32(Console.ReadLine());
for(i=3; i<=n/2; i++) you will find solution

using System;
using System.Collections.Generic;
using System.Linq;
public class assignment_4_Solution
{
public static void Main()
{
int n, i, flg1=1,flg2=1,flg3=0,j;

Console.Write("Enter a positive integer: ");
n = Convert.ToInt32(Console.ReadLine());
for(i=3; i<=n/2; i++)
{
/*---------- check for prime---------------*/
flg1=1;
flg2=1;
for(j=2; j<i; j++)
{
if(i%j==0)
{ flg1=0;j=i;}
}
for(j=2; j<n-i; j++)
{
if((n-i)%j==0)
{ flg2=0;j=n-i;}
}
if(flg1==1 && flg2==1)
{ Console.Write("{1} + {2} = {0} \n",n,i,n-i);
flg3=1;}
}
if(flg3==0)
{Console.Write("{0} can not be expressed as sum of two prime numbers.\n\n",n);}
}
}

RSS

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service