I want a hlep to write this program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • isabelle
    New Member
    • Dec 2006
    • 14

    I want a hlep to write this program

    1-Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, it should output the individual digits of 3456 as 3 4 5 6, output the individual digits of -2345 as 2 3 4 5.
    I see this program in this site and no body reply it, am really need the solution of it because this question is in my assignment.
    please help me?
  • sala
    New Member
    • Nov 2006
    • 12

    #2
    first i want to tell that i wrote as you the problem without trying and i wait for the answer but anyone send me a reply, for that i learn to search the algorithm from the internet , so what i wrote below is just what i found in my search; if it is not enough you could search further, good luck ;-)

    // Run through each single digit to create a new string. Even digits
    // are multiplied by two, odd digits are left alone.

    t = " ";
    for (i = 0; i < r.length; i++) {
    c = parseInt(r.char At(i), 10);
    if (i % 2 != 0)
    c *= 2;
    t = t + c;
    }

    // Finally, add up all the single digits in this string.

    n = 0;
    for (i = 0; i < t.length; i++) {
    c = parseInt(t.char At(i), 10);
    n = n + c;
    }

    Once the sum is found, the code checks to see if it's an even multiple of ten (i.e., n % 10 leaves no remainder).

    // If the resulting sum is an even multiple of ten (but not zero), the
    // card number is good.

    if (n != 0 && n % 10 == 0)
    return true;
    else
    return false;
    }

    Comment

    • suganya
      New Member
      • Dec 2006
      • 39

      #3
      Try this.

      void main()
      {
      unsigned int n,i=0,j=0;
      char a[10],temp;
      printf("\n Enter any positive integer value");
      scanf("%d",&n);
      do{
      a[i++] = '0' + n%10;
      n = n/10;
      }while(n!=0);
      a[i] = 0;
      i--;
      while(i>j)
      {
      temp = a[j];
      a[j++] = a[i];
      a[i--] = temp;
      }
      printf("\n The string is %s",a);
      getch();
      }

      Comment

      Working...