Sorting 3 Numbers and Even/Odd Questions

  • Thread starter Thread starter new c++er
  • Start date Start date
  • Tags Tags
    Numbers Sorting
Click For Summary

Discussion Overview

The discussion revolves around writing a C++ program that takes three numbers as input and sorts them in ascending order. Additionally, there is a question regarding the use of the cmath library in determining even and odd numbers.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant requests help with writing a C++ program to sort three numbers in ascending order and asks if cmath can differentiate between even and odd numbers.
  • Another participant points out that the forum rules require the original poster to make an attempt at a solution before receiving help.
  • A participant questions the relevance of knowing whether numbers are even or odd in the context of sorting them.
  • One participant clarifies that cmath refers to the math.h header and explains that the modulo operator (%) is sufficient to determine if a number is even or odd.
  • A Perl code snippet is provided as an example of sorting numbers, but it is noted that this may not be helpful for someone writing C++ code.

Areas of Agreement / Disagreement

Participants generally agree on the need for the original poster to attempt a solution first. However, there is no consensus on the relevance of the cmath library for the problem at hand, and the discussion about sorting methods remains unresolved.

Contextual Notes

The original poster has not attempted to write any code, which may limit the effectiveness of the responses. The discussion also reflects a mix of programming languages (C++ and Perl), which could lead to confusion regarding the appropriate solutions.

new c++er
Messages
4
Reaction score
0
hello everyone
i want your expert and your help please
i have to write a program that takes three numbers as input and write them in ascending order.
Sample Program Run:
Enter three numbers: 4 8 3
Numbers in ascending order: 3 4 8
how can i do it ?!:cry:
and i want to ask you does the cmath knows the diffrence between even numbers and odd numbers ?!

please consider that am a very first level in c++ and i need your help :blushing::cry:


thanks all
 
Physics news on Phys.org


new c++er said:
hello everyone
i want your expert and your help please
i have to write a program that takes three numbers as input and write them in ascending order.
Sample Program Run:
Enter three numbers: 4 8 3
Numbers in ascending order: 3 4 8
how can i do it ?!:cry:
and i want to ask you does the cmath knows the diffrence between even numbers and odd numbers ?!

please consider that am a very first level in c++ and i need your help :blushing::cry:


thanks all
That's concerns...

What have you tried to do? The rules of the forum say that you need to make an attempt at a solution before anyone can help you. See Homework Help here: https://www.physicsforums.com/showthread.php?t=5374.

What's "the cmath?" How would it help to know whether the numbers are even or odd? That's not anything that's relevant in this problem.
 
Last edited:
i'll check the link now :) !
but abt the cmath its another question not realted to the first one :D!
 
i haven't tried anything for honosty!
 
cmath is the header math.h. You don't need any of the functions whose prototypes are in math.h if all you want to do is determine whether a number is even or odd. The modulo or remainder operator (%) is all you need. You don't need to include any headers to use it.

This operator takes two operands, and returns the remainder when the first operand is divided by the second.
For example 5 % 2 == 1, and 8 % 2 == 0.
 
wt abt the acending thingy?!
 
Take a stab at it and then show me what you've tried.
 
#!perl
print "Enter three numbers: ";
print "Numbers in ascending order: ".join(" ",sort {$a <=> $b} (split /\D+/,<>))."\n";

DaveE
 
davee123 said:
#!perl
print "Enter three numbers: ";
print "Numbers in ascending order: ".join(" ",sort {$a <=> $b} (split /\D+/,<>))."\n";

DaveE
That's not going to be much help to the OP since he will be writing C++ code.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 12 ·
Replies
12
Views
2K
Replies
33
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K