473,804 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Program...

7 New Member
Hey guys, can you help me with this? C programming major in Turbo c. LOL


Well, this is my problem.

Create a program that accepts 10 positive integers. The program will group and sort all even and odd numbers. Even numbers will be sorted in ascending while odd numbers will be sorted in descending order. If theres is no even numbers found the program will print "NO even numbers" yet it prints the odd numbers, and sort it vice versa.

Use if statements or loops only.(turbo c)(no arrays or gotoxy() ]
please do help me.....

SAMPLE OUTPUT 1:
Enter 10 integers: 1 2 3 4 5 6 7 8 9 10

DISPLAYS:
even numbers:
+--------------------------+
| 2 4 6 8 10 |
+--------------------------+
odd numbers:
+---------------------------+
| 1 3 5 7 9 |
+---------------------------+
sorted even numbers:
+---------------------------+
| 2 4 6 8 10 |
+---------------------------+
sorted odd numbers:
+---------------------------+
| 9 7 5 3 1 |
+---------------------------+

SAMPLE OUTPUT 2:

ENTER TEN INTEGERS: 2 4 6 8 10 24 12 26 56 90

DISPLAYS:

NO ODD NUMBERS!

EVEN NUMBERS: 2 4 6 8 10 24 12 26 56 90
SORTED EVEN: 2 4 6 8 10 12 24 26 56 90


Thanks MORE POwer!
Nov 30 '06
14 6493
MabZiCLe
7 New Member
hmm..well, if no odd/even numbers? still, it will sort?
Jan 3 '07 #11
DeMan
1,806 Top Contributor
Depending on how you implemented your data structure, it could sort irrelevant of what the actual valueas are (that is, whether they are odd, even or a random mixture of both).
Even with arrays you could use almost any type of sort, but a structure like a linked list (which is reasonably easy to implement) may be more eficient. If you are really keen you could try creating a simple binary tree - a structure which beasically stores, adds and deletes elements in a way that is always sorted (if you really wanted to do some work, you could implement a balanced binary tree, which is space efficient, while still holding all the properties of the binary tree.....)
Jan 4 '07 #12
tavianator
38 New Member
I think the best way to do that without using arrays is to have ten ints (i0, i1 ... i9) and instead of loops, just modify each directly. Since you only have to input ten numbers, this will work.
Jan 4 '07 #13
DeMan
1,806 Top Contributor
sorting ten integers in ten variables can become REALLY messy (though not impossible), so I would think you need at least 11 variables (a temporary one is always nice), I'm not entirely sure how
instead of loops, just modify each directly
would work for sorting.....

Of course, one option would be to sort the numbers dynamically as they're entered (we put them all in order irrespective of odd/even and then as needed iterate through all testing if they are odd <or even>). To do this :

entry 1 goes in i1
if entry2 > i1 it goes in i2, else i1 goes in i2 and entry 2 goes in i1 (watch out!!! this can get complex even with temp variables......

TBC
Jan 5 '07 #14
reon
80 New Member
You can simply use this method for entering just one number and know it is odd or even


#include<iostre am.h>
#include<conio. h>
void main()
{
clrscr();
int a;
cout<<"Enter a number";
cin>>a;
if(a%2==0)
{
cout<<"Even numbers are :"<<a;
}
else
{
cout<<"\nNo even number";
}


if(a%2!=0)
{
cout<<"odd numbers are :"<<a;
}
else
{
cout<<"\nNo odd numbers";
}
getch();
}
Feb 2 '07 #15

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

Similar topics

3
3704
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example program #include <list>
17
6531
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual interest rate I, and annual service charge S. Your algorithm would then compute and print out the total amount of interest earned during the year and the final account balance at the end of the year (assuming that interest is compounded monthly, and...
11
2720
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
5
7252
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files, two aspects which I want to incorporate into my program eventually. That aside, my most pressing problem right now is how to get rid of the newline in the input when I use fgets(). Now I have looked around on the net, not so much in this group...
10
2381
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when there is such information to be displayed are they coming from imported files, database ? Where and how this type of information is stored ? What is the way to retrieve such information in order to display it in page ?
10
1950
by: Andrew | last post by:
Sorry about this but I'm new to ADO.NET (finally coming from simple ADO, bless it) and I'm trying to create a simple three tier program. Ie, User interface Layer / Business object layer / Database layer I've got a simple program that is activilly populating and writing my satasets. They are currently only mapping the database tables.So 1 dataset, 5 datatables and several relationships. In this program I can't seem to hide the database...
4
2392
by: Break2 | last post by:
I am trying to write a simple program which asks a user to enter 5 integers after which the average will be computed and written to the screen. That simple. However I want to do it according to a standard I used before to write a program which asked a user to enter the current year and his birthyear after which the current age of the user was computed and written to the screen. I got some help with the second program from some of you, thanks...
30
3554
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
1
2077
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that is about 3 and a half pages of code long it does some relatively simple math additions and subtractions The problem I have is that some numbers get to be very large integers and VB automatically converts this to scientifc notation, what I need is...
17
5829
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /* Simple Thread Object ______________________________________________________________*/ #include <pthread.h> extern "C" void* thread_entry(void*);
0
9711
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
9593
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
10595
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
10343
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
10335
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
5529
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...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
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
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.