Sign in to follow this  
Followers 0
Jamayka

help with pascal coding fast plz

5 posts in this topic

Hey guys can someone help me with this

Write an algorithm analysis and pascal program that write an integer n, one assumes that it is formed of four digits and then forming and displaying an entire r with the same figures but in opposite directions

0

Share this post


Link to post
Share on other sites

You need a program that flips an integer? 1234 -> 4321?

 

This can be done easily with modular arithmetic. Here is a code snippet in C that can be easily converted if you've paid attention in class.

int main()
{
   int n, reverse = 0;
 
   printf("Please enter an integer to reverse: ");
   scanf("%d", &n);
 
   while (n != 0)
   {
      reverse = (reverse * 10);
      reverse = (reverse + (n % 10));
      n = (n/10);
   }
 
   printf("The reverse of the entered number is = %d\n", reverse);
 
   return 0;
}
0

Share this post


Link to post
Share on other sites

@up, done with a class :sir:

 

the lazy way would be to convert int to string and switch order of elements and cast it back to int :dumb:

0

Share this post


Link to post
Share on other sites

@up, done with a class :sir:

 

the lazy way would be to convert int to string and switch order of elements and cast it back to int :dumb:

It's seriously only about 5 lines of code in pascal. 

0

Share this post


Link to post
Share on other sites

Actually, the lazy way is to post your homework assignment on a bulletin board and get someone to code it up for you. :-)

1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  
Followers 0