9 Replies - 602 Views - Last Post: 23 August 2013 - 08:11 AM Rate Topic: -----

#1 melon.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-August 13

visual studio 2010, loops.

Posted 23 August 2013 - 12:51 AM

Write a VB (Console Application) program that reads an integer number from keyboard
and determines if the given integer is a prime number or not. The program should give an appropriate
message accordingly. By definition a prime number is a natural number (>1) that has no divisors
except 1 and itself. Using your program determine which of the followings is a prime number:
0, 271, 47, 31, 97, 131

this is the question and i have got no idea where to start. i would really appreciate it if someone could help me onto the right path towards completing this.

Is This A Good Question/Topic? 0
  • +

Replies To: visual studio 2010, loops.

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3177
  • View blog
  • Posts: 10,639
  • Joined: 12-December 12

Re: visual studio 2010, loops.

Posted 23 August 2013 - 01:46 AM

What code do you have so far? Post it wrapped in CODE tags.

Are you attending a class, reading a book?
Was This Post Helpful? 0
  • +
  • -

#3 melon.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-August 13

Re: visual studio 2010, loops.

Posted 23 August 2013 - 01:57 AM

i havent got anything so far because i keep changing my mind on how to do it.
but now i know i have to do it via loops.

im doing this computations course at uni and its killing me. the lecturer hasnt really done any examples or anything like this
Was This Post Helpful? 0
  • +
  • -

#4 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 106
  • View blog
  • Posts: 596
  • Joined: 01-October 08

Re: visual studio 2010, loops.

Posted 23 August 2013 - 05:04 AM

Here is a start. If you don't know what things do look them up on MSDN (http://msdn.microsof...y/ff361664.aspx).

Module Module1

    Sub Main()
        Dim conIn As String = " "
        Dim anum As Integer = -1

        Do While conIn.ToLower <> "x"
            Console.WriteLine("Enter a number to check, x to exit")
            conIn = Console.ReadLine.Trim
            If Integer.TryParse(conIn, anum) Then
                'it is a number, and the number is in anum
                Debug.WriteLine(isPrime(anum))
                Stop
            End If
        Loop
    End Sub

    Public Function isPrime(someNumber As Integer) As Boolean
        'check for prime
    End Function

End Module


This post has been edited by dbasnett: 23 August 2013 - 05:48 AM

Was This Post Helpful? 1
  • +
  • -

#5 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 431
  • View blog
  • Posts: 2,989
  • Joined: 12-January 10

Re: visual studio 2010, loops.

Posted 23 August 2013 - 05:14 AM

you can use mod to see the numbers

like

mod 2 = 0


the above should return all even numbers

mod 2 = 1

should return all odd numbers

you will have to write an if statement and maybe a loop -- but I am not doing your homework so good luck.

You can post your current work and we will help you out.
Was This Post Helpful? 0
  • +
  • -

#6 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 177
  • View blog
  • Posts: 1,087
  • Joined: 11-May 12

Re: visual studio 2010, loops.

Posted 23 August 2013 - 05:19 AM

Daren, the user isn't looking for just even or odd numbers, they are looking for prime numbers. He could use hat as well though, because the only even prime number is 2. so to speed things up, they could check for if the number is not even and the number is not 2 then start looping.
Was This Post Helpful? 0
  • +
  • -

#7 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 964
  • Joined: 09-May 09

Re: visual studio 2010, loops.

Posted 23 August 2013 - 07:32 AM

http://www.dailyfree...-code-3346.aspx

there you go, but i suggest giving it a bit of jazz
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,369
  • Joined: 12-June 08

Re: visual studio 2010, loops.

Posted 23 August 2013 - 07:35 AM

... yes, because if the OP is so lost (or doesn't know where to start) s/he doesn't get loops or if statements then a chunk of undocumented (or unexplained) code will help the learning process.
Was This Post Helpful? 0
  • +
  • -

#9 ybadragon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 177
  • View blog
  • Posts: 1,087
  • Joined: 11-May 12

Re: visual studio 2010, loops.

Posted 23 August 2013 - 07:47 AM

Also the link you provided doesn't give prime numbers. It returns True if the number is an odd number. As I posted previously not all odd numbers are Prime. 9 is an example. it's divisible by 1, 3, and 9.
Was This Post Helpful? 0
  • +
  • -

#10 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 431
  • View blog
  • Posts: 2,989
  • Joined: 12-January 10

Re: visual studio 2010, loops.

Posted 23 August 2013 - 08:11 AM

View Postybadragon, on 23 August 2013 - 10:47 AM, said:

Also the link you provided doesn't give prime numbers. It returns True if the number is an odd number. As I posted previously not all odd numbers are Prime. 9 is an example. it's divisible by 1, 3, and 9.



agreed but like mine and the link poster --- I was not trying to give him code that would directly answer his question since he showed zero effort. I was showing him code to get him started in learning on how to do certain maths which he could then derive info from.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1