problem not solving-five digit number input through key board ,write program to calculate sum of its digits

1 reply [Last post]
Joined: 04/17/2010

#include
#include

int main()
{
int i;
printf("Enter a four digit number:");
scanf("%d",&i);
printf("You entered :%d nReverse number:%d",i,i%10);
i=i/10;
printf("%d", i%10);
i=i/10;
printf("%d", i%10);
i=i/10;
printf("%d", i%10);
i=i/10;
getch();
}

yogendra's picture
User offline. Last seen 1 day 12 hours ago. Offline
Joined: 01/06/2010
Correct Solution

 

int main()

{

     int num, i, rev_num;

     printf("Enter a four digit number:");

     scanf("%d",&num);

     printf("You entered :%d",num);     

     

     i = num % 10;

     rev_num = i * 1000;

     num = num / 10;

     

     i = num % 10;

     rev_num = rev_num + i * 100;

     num = num / 10;

     

     i = num % 10;

     rev_num = rev_num + i * 10;

     num = num / 10;

     

     i = num % 10;

     rev_num = rev_num + i * 1;

     

     printf("Reverse number %d",rev_num);

     getch();

 }

 

Dear. Mr. Parveen.

 

This is the correct answer of your problem. This is not the correct place to ask your problems. You are a paid students and you can ask your questions directly on moodle.learnbywatch.com

 

Forums are available for you at moodle.learnbywatch.com please go there and start discussions about your problem. Thank you.

Yogendra Pal

Learn By Watch

yogendra@learnbywatch.com