helllo guys. I'm having problem with this question:
Write a program in C involving the use of pointers to reorder a list of numbers so that any of the following arrangements can be carried out :
a) smallest to largest by magnitude
b) smallest to largest, algebraic (by sign)
c) largest to smallest, by magnitude
d) largest to smallest, algebraic
Here is my coding:
Code:
#include <stdio.h>
#include<math.h>
void main()
{
int selection,count;
float nums[10];
printf("\n**************************MENU********************");
printf("\n 1. reorder from smallest to largest, by magnitude");
printf("\n 2. reorder from smallest to largest, algebraically");
printf("\n 3. reorder from largest to smallest, by magnitude");
printf("\n 4. reorder from largest to smallest, algebraically");
printf("\n****************************************************");
printf("\n Enter your selection please:");
scanf("%d",&selection);
for(count=0;count<=9;++count)
{
printf("\nEnter a number:");
scanf("%d",&nums[count]);
}
switch (selection)
{
case 1:
reorder1(nums);
break;
case 2:
reorder2(nums);
break;
case 3:
reorder3(nums);
break;
case 4:
reorder4(nums);
break;
}
getchar();
}
int reorder1(float nums[])
{
float item,temp;
int count,a;
for (item=0;item<=9;++item)
for (a=item+1;a<=9;++a)
if(abs(nums[item])>abs(nums[a]))
{
temp=nums[item];
(nums[item])=(nums[a]);
(nums[a])=temp;
}
for (count=0;count<=9;++count)
{
printf("%f",nums[count])
printf("\n");
}
return;
}
int reorder2(float nums[])
{
float item,temp;
int count,a;
for (item=0;item<=9;++item)
for (a=item+1;a<=9;++a)
if((nums[item])>(nums[a]))
{
temp=nums[item];
nums[item]=nums[a];
nums[a]=temp;
}
for (count=0;count<=9;++count)
{
printf("%f",nums[count])
printf("\n");
}
return;
}
int reorder3(float nums[])
{
float item,temp;
int count,a;
for (item=0;item<=9;++item)
for (a=item+1;a<=9;++a)
if(abs(nums[item])<abs(nums[a]))
{
temp=nums[item];
nums[item]=nums[a];
nums[a]=temp;
}
for (count=0;count<=9;++count)
{
printf("%f",nums[count])
printf("\n");
}
return;
}
int reorder4(float nums[])
{
float item,temp;
int count,a;
for (item=0;item<=9;++item)
for (a=item+1;a<=9;++a)
if(nums[item]<nums[a])
{
temp=nums[item];
nums[item]=(nums[a]);
nums[a]=temp;
}
for (count=0;count<=9;++count)
{
printf("%f",nums[count])
printf("\n");
}
return;
}
Im having about 30 errors while im trying to build the program...
Someone please help....