473,385 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Simple Program...

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 #1
14 6455
sivadhas2006
142 100+
Hi,

Do u have any code?
If have please post it.

Regards,
M.Sivadhas.
Nov 30 '06 #2
Expand|Select|Wrap|Line Numbers
  1.  //this programmay help you 
  2.  
  3. #include<stdio.h>
  4. main()
  5. {
  6. int j=0,temp=0,ea[10],oa[10],i=0,e=0,o=0,n;
  7.  
  8. for(i=0;i<10;i++)
  9. {
  10. printf("Enter number");
  11. scanf("%d",&n);
  12.  
  13. if(n%2==0)
  14. ea[e++]=n;
  15. else
  16. oa[o++]=n;
  17. }
  18. if(e==0)
  19.  
  20. printf("No Even numbers:\n");
  21. else
  22. {
  23. printf("Even numbers:\n");
  24. for(i=0;i<e-1;i++)
  25. {
  26. for(j=i+1;j<e;j++)
  27. {
  28. if(ea[i]>ea[j])
  29. {
  30. temp=ea[i];
  31. ea[i]=ea[j];
  32. ea[j]=temp;
  33. }
  34. }
  35. }
  36. for(i=0;i<e;i++)
  37. printf("%d\t",ea[i]);
  38. printf("\n");
  39. }
  40. if(o==0)
  41.  
  42. printf("No odd numbers:\n");
  43. else
  44. {
  45. printf("Odd numbers:\n");
  46.  
  47. for(i=0;i<o-1;i++)
  48. {
  49. for(j=i+1;j<o;j++)
  50. {
  51. if(oa[i]>oa[j])
  52. {
  53. temp=oa[i];
  54. oa[i]=oa[j];
  55. oa[j]=temp;
  56. }
  57. }
  58. }
  59. for(i=0;i<o;i++)
  60. printf("%d\t",oa[i]);
  61. }
  62. }
  63.  
Nov 30 '06 #3
DeMan
1,806 1GB
And what is the exact problem.....
Nov 30 '06 #4
Manjiri
40
//this programmay help you

#include<stdio.h>
main()
{
int j=0,temp=0,ea[10],oa[10],i=0,e=0,o=0,n;

for(i=0;i<10;i++)
{
printf("Enter number");
scanf("%d",&n);

if(n%2==0)
ea[e++]=n;
else
oa[o++]=n;
}
if(e==0)

printf("No Even numbers:\n");
else
{
printf("Even numbers:\n");
for(i=0;i<e-1;i++)
{
for(j=i+1;j<e;j++)
{
if(ea[i]>ea[j])
{
temp=ea[i];
ea[i]=ea[j];
ea[j]=temp;
}
}
}
for(i=0;i<e;i++)
printf("%d\t",ea[i]);
printf("\n");
}
if(o==0)

printf("No odd numbers:\n");
else
{
printf("Odd numbers:\n");

for(i=0;i<o-1;i++)
{
for(j=i+1;j<o;j++)
{
if(oa[i]>oa[j])
{
temp=oa[i];
oa[i]=oa[j];
oa[j]=temp;
}
}
}
for(i=0;i<o;i++)
printf("%d\t",oa[i]);
}
}

Hi Rashmi...

your program gives the output...
But Plz put the statement"Enter your numbers" outside the for loop...
Otherwise for each and every number it will output "Enter you number"..
And the person has also asked you to group the odd numbers and even numbers saparately then print them in order...

Hope my suggestion is ok for you..
Regards
Manjiri
Dec 1 '06 #5
hi manjiri
thanks for your suggestion
here it toring even and odd numbers in seperate arrays(ea and oa) and then i am sorting.
Dec 1 '06 #6
Manjiri
40
hi manjiri
thanks for your suggestion
here it toring even and odd numbers in seperate arrays(ea and oa) and then i am sorting.
Hi Rashmi

Ya ya you are right... but see the problem also tells you to print them separately before you sort them... You see the required output once again...
you are not outputting the group of odd and even numbers(before sorting) where it is required to do that...

Hope you got me now...
Dec 1 '06 #7
Manjiri
40
hi manjiri
thanks for your suggestion
here it toring even and odd numbers in seperate arrays(ea and oa) and then i am sorting.

Hi Rashmi

One more thing.. you are printing the odd numbers in ascending order... where problem asks you to print it in descending order...

Regards
Madhuri
Dec 1 '06 #8
w000.... i need while/if statements..not using arrays.. =((
Dec 3 '06 #9
DeMan
1,806 1GB
You could store them all in a string,....wait a minute that's an array too. That means you qwould have to use some other type of data structure (which to me seems a peculiar requirement, unless thew idea is for you to implement some data type). Have you considered this approach, and if so please post any progress
Dec 5 '06 #10
hmm..well, if no odd/even numbers? still, it will sort?
Jan 3 '07 #11
DeMan
1,806 1GB
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
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 1GB
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
You can simply use this method for entering just one number and know it is odd or even


#include<iostream.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
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
17
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...
11
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
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,...
10
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...
10
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...
4
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...
30
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
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...
17
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: _________________________________________________________________ /*...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.