473,508 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help the program wont display ODD numbers

18 New Member
This works and shows the factors or tells if the number is a prime number but doesn't show ODD factors please help!! I need to turn this tomorrow
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;     
  3. int prime(int num);
  4. int main()
  5. {
  6. int num;
  7. cout<<"Enter number: ";
  8. cin>>num;
  9. if(prime(num)==1)
  10. cout<<"The number is prime";
  11. else
  12. cout<<"The number is not prime, factors are\n1\n";
  13. if( num%2==0)
  14.  for(int j=2;j<num;j+=2)
  15.  {
  16.  if(num%j==0)
  17.  cout<<j<<endl;
  18.  }
  19.  for( int n=num;n<=num;n/=2)
  20.  {
  21.  if(num%n==0)
  22.  cout<<n<<endl;
  23.  }
  24.  for(int m=3;m<num;m+=3)
  25.  {
  26.  if(num%m==0)
  27.  cout<<m<<endl;
  28.  }
  29. }
  30. }
  31. int prime(int num)
  32. {
  33.     if(num <= 1)
  34.     {
  35.          return false;
  36.     }
  37.     if(num == 2)
  38.     {
  39.          return true;
  40.     }
  41.     if ( num%2 == 0)
  42.     {
  43.        return false;
  44.     }
  45.  
  46.     for (int n=3;n*n <= num;n+=2)
  47.     {   if (num%n == 0)
  48.            return false;
  49.     }
  50.     return true;
  51.     }
  52.  
Jan 11 '08 #1
1 1636
sicarie
4,677 Recognized Expert Moderator Specialist
Wow, I would go back and review your algorithm, there are many logic and syntax errors. Due to the logic errors, I don't think it would be worth fixing the syntax errors - you should re-do your algorithm so that you don't have three conditions in your function that can all be true at the same time and return different values.

Also, please check your Private Messages - accessible through the PMs link in the top right corner of the page.
Jan 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3870
by: Roy J | last post by:
Hello everyone:) My name is Roy, I am new to Java and I have problem regarding to arrays. if you have time and like to help, please help. I am trying to make a program to deal with prime...
5
1532
by: johny | last post by:
Program details as follows: Input to the program the exam number and computer arch and programming results for 10 people. Three arrays - ExamNo, Arch and prog are used to hold these items. The...
9
6864
by: ehabaziz2001 | last post by:
I am facing that error message with no idea WHY the reason ? "Abnormal program termination" E:\programs\c_lang\iti01\tc201\ch06\ownarr01o01 Enter a number : 25 More numbers (y/n)? y...
1
2249
by: Tigerlily | last post by:
// Program to create new accounts, perform deposits, withdrawals, and bank //inquiries #include<iostream> #include<fstream> using namespace std; void menu(); int read_accts(int , double ,...
1
2554
by: parasuit | last post by:
HI every body I need following programs for java .........please urgent i m biggner so help me................but urgent Problem # 1 An integer is said to be prime if it is...
4
2076
by: Kausar.Nazir | last post by:
Pronlem# 1: How can I Create a notepad file named number.txt which consists of int type numbers separated with new lines on your hard disk, a program which read the numbers form this file and show...
2
1042
by: Kaizashi | last post by:
Hello all~ sorry for bothering you all like this but I have an assignment that I have to give to my doctor on Wednsday 5/12/2007, and there are 3 Questions that I cant seem to make a program out of...
5
1396
by: katie smith | last post by:
Here is the program I just started, The problem i am having is I'm trying to get it to load the image file Sand1 with eval(loader) = pygame.image.load(loader) because Loader is euqual to "Sand1" but...
4
2965
by: dragony2000 | last post by:
I want to solve these questions using C# , Please !!! ************************************************************* 1- The factorial method is used frequently in probability problems. The...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.