Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 A Particular Sort
Index -> Programming, C -> C Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rar




PostPosted: Tue Feb 02, 2010 3:30 pm   Post subject: RE:A Particular Sort

Never mind, I figured out what was wrong with that code.

Now I just need to figure out how to make this a recursive function to use in my actual sort program.

code:

#include <stdio.h>
#include <stdlib.h>

#define n 50

void function(int);

int main()
{
    puts("number");
    int n;
    scanf("%d", &n);
    function(n);
}

void function(int n)
{

    int temp = n;
    int count;

    for(count = 0; temp > 10; count++) //divides the number by 10 until only one digit remains, so as to find the first digit. also, the count variable is counting how many times this division is required, which essentially is counting how many digits.
    {
        temp = temp / 10;
    }
    count++;
    printf("number of digits = %d\n", count);
    printf("Digit 1 = %d\n", temp);

    int c2;
    int temp2 = temp;

    for(c2 = 0; c2 <= count + 1; c2++); //multiplying the number by 10 to the power of the number of digits
    {
        temp *= 10;
    }
    temp *= 10;
    int result = n - temp;
    printf("%d - %d = %d\n", n, temp, result);

}






Indentation helps - wtd
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 16 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: