473,668 Members | 2,639 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 1645
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
3884
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 numbers, but I do not how to involve arrays with that. program generates prime numbers according to user input, and displays them in descending order. The user enters the number of prime numbers to be generated. The output is displayed 5 numbers per...
5
1551
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 First name and surname of each student should also be entered, concatenated into one string and output to an array called wholename We need to check weather the exam numbers are valid. An exam number should consist of 7 digits only Include a...
9
6886
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 Enter a number : 30 More numbers (y/n)? n
1
2256
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 , int); void withdrawal(int , double , int); void deposit(int , double , int); int new_acct(int , double , int);
1
2559
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 divisible only by 1 and itself. Write a method that determines whether a number is prime. Use this method is an applet that determines and prints all the prime numbers less than 10,000
4
2084
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 them to screen, also display the total numbers in files and largest and smallest numbers to the screen. Please guide me I will be very thank full to you. problem # 2: Write a simple structure named Students. This structure consists of three...
2
1046
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 it.my lecture doctor isnt very good and helpful. I'll be forever thankful for your help! Q1) Write a program to read 30 numbers, and ask the user about the value, whos interested in it, and display all psitions that contains it. eg:...
5
1407
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 It wont load it. If I set it as loader = pygame.image.load(loader) then it sets the image to the variable loader. So I'm basically trying to set a string equal to a surface variable. I dont want to have to go Sand1 = pygame.image.load("Sand1.bmp")...
4
2975
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 factorial of a positive integer n (written n! and pronounced “n factorial”) is equal to the product of the positive integers from 1 to n. Write a program that evaluates the factorials of the integers from 1 to 20 with different integer data types....
0
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8797
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8583
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8656
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2791
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 we have to send another system
2
1786
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.