convert 12345 to 54321 withoutusing strig

Answers were Sorted based on User's Feedback



convert 12345 to 54321 withoutusing strig..

Answer / abhradeep chatterjee

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
printf("enter a number");
scanf("%d",&i);
for(int n=1;n<=5;n++)
{
j=i%10;
i=i/10;
printf("%d",j);
}
getch();
}

Is This Answer Correct ?    5 Yes 4 No

convert 12345 to 54321 withoutusing strig..

Answer / pavan kumar b n

By making use of stack data structure.... i.e., first push
all the numbers and then pop them .. since stack is LIFO
order , the numbers get reversed....

Is This Answer Correct ?    1 Yes 0 No

convert 12345 to 54321 withoutusing strig..

Answer / satrughna sethi

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
printf("enter a number");
scanf("%d",&i);
for(int n=1;n<=5;n++)
{
j=i%10;
i=i/10;
printf("%d",j);
}
getch();
}

Is This Answer Correct ?    5 Yes 5 No

convert 12345 to 54321 withoutusing strig..

Answer / ismail

void main()
{
long num, temp;
for(;;) {
printf("Enter number:");
scanf("%ld",&num);
if(num == 0) break;
while(num) {
temp = num%10;
num = num/10;
printf("%ld", temp);
}
printf("\n");
break;
}
getch();
}

Is This Answer Correct ?    0 Yes 0 No

convert 12345 to 54321 withoutusing strig..

Answer / mani bhowmik

void main()
{
int num, temp;
for(;;) {
printf("Enter number:");
scanf("%d",&num);
if(num == 0) break;
while(num) {
temp = num%10;
num = num/10;
printf("%d", temp);
}
printf("\n");
}
getche();
}
So any number will be reversed here. 12345 is five digit
number. Using while we can generalize the number of digits.
The continuous loop is ended when 0 is entered.

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More C Interview Questions

What is static and volatile in c?

0 Answers  


/*program to calculate hra,da in salary if salary less than 10000 then hra15%,da13% otherwise hra20%,da18%/*

6 Answers  


Differentiate between #include<...> and #include '...'

0 Answers  


What is the purpose of void in c?

0 Answers  


Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80

0 Answers  






my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

0 Answers  


Explain what are binary trees?

0 Answers  


Why c is a procedural language?

0 Answers  


What is the difference between printf and scanf in c?

0 Answers  


In C programming, what command or code can be used to determine if a number of odd or even?

0 Answers  


What is sizeof return in c?

0 Answers  


while initialization of two dimensional arrays we can initialize like a[][2] but why not a[2][] is there any reason behind this?

4 Answers   Aptech,


Categories