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!
14 6492
Hi,
Do u have any code?
If have please post it.
Regards,
M.Sivadhas.
- //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]);
-
}
-
}
-
DeMan 1,806
Top Contributor
And what is the exact problem.....
//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
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 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...
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
w000.... i need while/if statements..not using arrays.. =((
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Patchwork |
last post by:
Hi Everyone,
Please take a look at the following (simple and fun) program:
////////////////////////////////////////////////////////////////////////////
/////////////
// Monster Munch, example program
#include <list>
|
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...
|
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:
|
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...
|
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 ?
| |
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...
|
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...
|
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
|
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...
|
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*);
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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
|
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...
| |