Reverse the part of the number which is present from
position i to j. Print the new number.[without using the array]
eg:
num=789876
i=2
j=5
778986
Answer Posted / abdur rab
#include <stdio.h>
int get_digits ( int number )
{
int n_digits = 0;
while ( number ) {
n_digits++;
number = number / 10;
}
return ( n_digits );
}
int main ( int argc, char* argv [] )
{
int number = 789876;
int digits = 0;
int temp_number = 0;
int final_number = 0;
int counter = 0;
int start_point = 2;
int end_point = 5;
digits = get_digits ( number );
if ( ( start_point < end_point ) && ( end_point <=
digits ) ) {
temp_number = number;
if ( start_point - 1 ) final_number =
number / pow ( 10, ( digits - ( start_point - 1 ) ) );
counter = digits;
while ( temp_number ) {
if ( ( counter <= ( end_point ) )
&& ( counter >= ( start_point ) ) ) {
final_number *= 10;
final_number += (
temp_number % 10 );
}
temp_number /= 10;
counter--;
}
if ( digits - end_point ) {
final_number *= pow ( 10, ( digits -
end_point ) );
final_number += number % (int) (
pow ( 10, ( digits - end_point ) ) );
}
}
printf ( "\n Number: %d", number );
printf ( "\nFinal Number: %d", final_number );
printf ( "\nS_Pos: %d, E_Pos: %d", start_point,
end_point );
return ( 0 );
}
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
How important is structure in life?
How do I determine whether a character is numeric, alphabetic, and so on?
How to set file pointer to beginning c?
What is c definition?
What is difference between array and pointer in c?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"
write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34
c program to compute AREA under integral
What does %c mean in c?
What is pass by reference in functions?
Explain data types & how many data types supported by c?
Write a C program in Fibonacci series.
What is array of structure in c programming?
What does s c mean on snapchat?