Tuesday, July 14, 2009

Please help me do this C program?

Write a program in C (using the %26lt;stdio.h%26gt; function) that reads any five digit number and displays the number in two parts


diagonally as shown in the user interface screen as in the figure below.


it's suppose to look like this (IGNORE the dotted lines):





Please key in any 5 digit number: 56789


5678 9


..567 89


....56 789


......5 6789





The number displayed is separated into two parts beginning with the rightmost unit digit. The


process continues until the leftmost digit is reached.


thanx alot k..

Please help me do this C program?
void main()


{


int number, row, column;


char digits[10];





printf("Please enter a 5-digit number: ");


scanf("%i", %26amp;number);


sprintf(digits, "%05i\n", number);


for (row=0; row%26lt;4; row++)


for (column=0; column%26lt;6; column++)


printf("%c%s",


digits[column],


(column==3-row) ? " " : "");


}
Reply:No problem, use this then....





// part1:





#include %26lt;stdio.h%26gt;





void printNum(int num, int digit, int pos)


{


if (digit == 5)


printf("\n");


else


{


printNum(num / 10, digit+1, pos);


printf("%i", num % 10);


if (digit == 4-pos)


printf(" ");


}


} Report It

Reply:// part 2:





void main()


{


int number, row;





printf("Please enter a 5-digit number: ");


scanf("%i", %26amp;number);


for (row=0; row%26lt;4; row++)


printNum(number, 0, 4-row-1);


} Report It

Reply:yea, thanx alot for the update.it really opens up new insights.. i would give u a five out of five now.. haha..





but i cant get it to look like this (da dots are for indentation purpose only):


1234 5


..123 45


.....12 345


.......1 2345


do not know why!!!!!!!! Report It

Reply:If it's a home work, then you should use your own imagination my friend!


No comments:

Post a Comment