473,796 Members | 2,460 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 #1
14 6492
sivadhas2006
142 New Member
Hi,

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

Regards,
M.Sivadhas.
Nov 30 '06 #2
rashmisn
2 New Member
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 Top Contributor
And what is the exact problem.....
Nov 30 '06 #4
Manjiri
40 New Member
//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",e a[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",o a[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
rashmisn
2 New Member
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 New Member
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 New Member
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
MabZiCLe
7 New Member
w000.... i need while/if statements..not using arrays.. =((
Dec 3 '06 #9
DeMan
1,806 Top Contributor
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

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

Similar topics

3
3702
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
6526
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
2717
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
7249
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
2379
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
1948
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
3550
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
5823
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
9673
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
9525
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
10452
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...
1
10169
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
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
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
4115
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
3
2924
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.