Question

Function Name: sepDigits Inputs: 1. (double) A three-digit integer Outputs: 1. (double) The hundreds-place digit of...

Function Name: sepDigits
Inputs:
1. (double) A three-digit integer
Outputs:
1. (double) The hundreds-place digit of the input
2. (double) The tens-place digit of the input
3. (double) The ones-place digit of the input
Function Description:
This function will take in a three-digit integer (integer between 100 and 999 , inclusive)
and should return each digit as a separate number. For example, if the input is 472 , the first
output would be 4 , the second would be 7 and the third would be 2 .
Notes:
● You only have to deal with three-digit positive integers.
● The mod() and floor() functions will do all the heavy lifting.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

//it is a c program to seperate the digits of a 3 digit number
#include<stdio.h>
void sepDigits(int n);
main(){
   int n;
   printf("\nEnter a 3 digit positive integer:");
   scanf("%d",&n);
   if(n<100||n>999){
       printf("\nInvalid input... please entere 3 digit positive integer");
   }
   else
       sepDigits(n);
   return 0;
}
void sepDigits(int n){
   int r,i=0;
   while(n!=0){
       i++;
       if(i==1){
           r=n/100;
           n=n%100;
           printf("\n%d",r);
       }
       else if(i==2){
           r=n/10;
           n=n%10;
           printf("\n%d",r);
       }
       else if(i==3){
           r=n;
           n=n%1;
           printf("\n%d",r);
       }
   }
}

OUTPUT:

C: Program Files (x86)\Dev-Cppl ConsolePauser.exe nter a 3 digit positive integer:783 rocess exited normally ress any key to

Add a comment
Know the answer?
Add Answer to:
Function Name: sepDigits Inputs: 1. (double) A three-digit integer Outputs: 1. (double) The hundreds-place digit of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT