Advertisement
Guest User

Yahav Q2

a guest
May 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int
  5. main ()
  6. {
  7. printf ("Please enter letters:\n");
  8. char ch;
  9. char closertoz;
  10. scanf (" %c", &ch);
  11. if (ch == '#')
  12. return 0;
  13. int disfromz = 0;
  14.  
  15. if (ch >= 'A' && ch <= 'Z')
  16. {
  17. disfromz = (int) ('Z' - ch);
  18. ch += ('a' - 'A');
  19. }
  20. else
  21. disfromz = (int) ('z' - ch);
  22.  
  23. closertoz = ch;
  24. int maximumfromz = disfromz;
  25. while (2 > 0)
  26. {
  27. scanf (" %c", &ch);
  28. if (ch == '#')
  29. {
  30. printf ("%c", closertoz);
  31. return 0;
  32. }
  33.  
  34. if (ch >= 'A' && ch <= 'Z')
  35. {
  36. disfromz = (int) ('Z' - ch);
  37. ch = (char) ((int) ch + ((int) ('a' - 'A')));
  38. }
  39. else
  40. disfromz = (int) ('z' - ch);
  41. if (disfromz < maximumfromz)
  42. {
  43. closertoz = ch;
  44. maximumfromz = disfromz;
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement