How do I print out something different at the last item of a loop, C programming -



How do I print out something different at the last item of a loop, C programming -

please come in integer: 1234 digit: 4 digit: 3 digit: 2 digit: 1

i have programme right prints out integer's digits in reverse. instead of output above, i'd have:

please come in integer: 1234 digit: 4 digit: 3 digit: 2 lastly digit: 1

how create happen? here's code way:

#include <stdio.h> int main() { int input; printf("please come in integer: "); scanf("%d", &input); int num = input; int = 0; while(num > 0) { int remainder = num % 10; num = num /10; i++; printf("digit: %d\n", remainder ); } homecoming 0; }

how print else @ lastly item of loop?

testing see if while status fail 1 way.

while (num > 0) { int remainder = num % 10; num = num / 10; i++; if (num > 0) { printf("digit: %d\n", remainder); } else { printf("last digit: %d\n", remainder); } }

or alter while condition...

while (num > 9) { int remainder = num % 10; num = num / 10; i++; printf("digit: %d\n", remainder); } printf("last digit: %d\n", num);

c

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -