RicardasSim

printf percent

Oct 2nd, 2020
1,785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     float total = 300.0f;
  7.  
  8.     float val = 30.0f;
  9.  
  10.     float percentage = val / total * 100.0f;
  11.  
  12.     printf("%.2f%%\n", percentage);
  13.  
  14.     printf("%% %% %%%%\n");
  15.  
  16.     return 0;
  17. }
  18.  
  19. /*
  20. output:
  21.  
  22. 10.00%
  23. % % %%
  24.  
  25. */
  26.  
Advertisement
Add Comment
Please, Sign In to add comment