Results 1 to 2 of 2

Thread: Simple Prime Factors Program

  1. #1
    Join Date
    Nov 2011
    Posts
    2

    Simple Prime Factors Program

    I need some help. Im just a begginer at programming. We started looping and i am stuck on one program. using dev C++. its to find prime numbers. this is what i have:

    #include <cstdlib>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[])
    {

    int number=0;
    int counter=2;

    cout<<"Enter a number: ";
    cin>>number;
    while (counter<=number) {
    if (counter%2==0){
    cout<<counter<<" ";
    number=number/counter;
    }
    else (counter%2==1); {
    counter=counter+1;
    }
    }


    system("PAUSE");
    return EXIT_SUCCESS;
    }


    The example we were given was the number 140. The answer should be: 2 2 5 7. Mine outputs the numbers: 2 4 6

    can anyone tell me whats wrong? keeping it simple because i am a begginer?

    Thank You!

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: Simple Prime Factors Program

    Can you try the below code:

    Code:
    #include<iostream>
    #include <conio.h> 
    using namespace std;
    int main()
    {
    
    int i, n;
    int fact=1;
    cout<<"\nEnter a number: ";
    cin>>n;
    for(i=n ; i>=1 ; i--)
    act = fact*i;
    cout<<"The factoral value is: "<<fact;
    getch();
    return 0;
    }#include<iostream>
    #include <conio.h> 
    <strong class="highlight">using</strong> namespace std;
    int main()
    {
    
    int i, n;
    int fact=1;
    cout<<"\nEnter a number: ";
    cin>>n;
    for(i=n ; i>=1 ; i--)
    fact = fact*i;
    cout<<"The factoral value is: "<<fact;
    getch();
    return 0;
    }

Similar Threads

  1. Best OC load test program - Prime or OCCT?
    By Fitroy in forum Hardware Peripherals
    Replies: 6
    Last Post: 12-07-2011, 10:42 PM
  2. How to develop simple program in ASP.NET 4.0
    By Daniela007 in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 11:57 PM
  3. Shell program for the prime number
    By Rup_me in forum Software Development
    Replies: 5
    Last Post: 14-12-2009, 10:24 AM
  4. program to print prime factor of given number
    By teena_pansare in forum Software Development
    Replies: 4
    Last Post: 27-11-2009, 10:21 AM
  5. To write first 100 prime numbers in c++ program.
    By supernoob in forum Software Development
    Replies: 3
    Last Post: 09-07-2009, 07:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,586,278.15181 seconds with 17 queries