In: Computer Science
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf())
Complete the following functions using C programming language:
Note: Use the division and remainder operators to separate the number into its individual digits.
I WROTE THE CODE ALONG WITH THE COMMENTS
CODE:
#include <stdio.h>
int Q7a(int Q7_input)
{
int digit,rev_num=0; //variables declaration.
while(Q7_input!=0) //condition number not equal to 0.
{
digit=Q7_input%10;
rev_num=rev_num*10+digit;
Q7_input=Q7_input/10;
}
return rev_num;
}
int main()
{
int num; //variable declaration.
printf("Enter seven_digit positive number: ");
scanf("%d",&num); //scan input.
int reverse_num=Q7a(num); //calling Q7a() funtion.
printf("Reverse number: %d",reverse_num);
return 0;
}
OUTPUT:
SCREENSHOT OF THE CODE: