Sunday, August 2, 2009

I need help regarding Turbo c proramming...?

The problem is this: Write a program that will accept 10 positive numbers from the user, then arrange the given numbers in descending order. (Hint: use loop within a loop(for-loop) and conditional if statement). tnx^-^

I need help regarding Turbo c proramming...?
What part are you stuck on?


Try writing the program in pseudo-code first, or at least the sorting algorithm.


Writing program logic out in pseudo-code first is useful because you don't have to worry about variable allocation and writing the code to handle the looping.





Pseudo-code example:


1) Print 'Enter a positive number'


2) get %26amp; store input


3) did the user input 10 numbers yet? If not, go back to 1.


4) get number and compare....I'll leave it up to you.





For the sorting algorithm, imagine if you had 10 sticks lying on the ground, all stacked up. Each stick has a number on it, and you want to find the stick with the highest number. So, you pick up each stick, one at a time, look at it, and....





EDIT---


That's it Angelina, do his homework for him...
Reply:main()


{


int a[10], i, j, temp;


printf("Enter 10 Positive integers");


for (i=0; i%26lt;10; i++)


scanf("%d", a[i]);


for (i=0; i%26lt;10; i++)


for (j=i+1; j%26lt;10; j++)


if (a[j] %26gt; a[i])


{


temp = a[i]


a[i] = a[j]


a[j] = temp


}


for(i=0; i%26lt;10; i++)


printf ("%d", a[i]);


}


No comments:

Post a Comment