rohit35

ADDRev

Mar 25th, 2018
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int a,b,T,cur,first,second,res;
  6. scanf("%d",&T);
  7. while(T--)
  8. {
  9. scanf("%d %d",&a,&b);
  10. first=rev(a);
  11. second=rev(b);
  12. cur=first+second;
  13. check(cur);
  14. res= rev(cur);
  15. printf("%d\n",res);
  16. }
  17. return 0;
  18. }
  19. void check(int res)
  20. {
  21. int idx=0;
  22. while(res>0)
  23. {
  24. if(res%10!=0)
  25. {
  26. idx=idx*10+res%10;
  27. }
  28. res/=10;
  29. }
  30. res=idx;
  31. }
  32. int rev(int num)
  33. {
  34. int idx=0;
  35. while(num>0)
  36. {
  37. idx=idx*10+num%10;
  38. num/=10;
  39. }
  40. num=idx;
  41. }
Add Comment
Please, Sign In to add comment