Advertisement
YouKnowWho07

divisible by 3 or 5 but not by both

Dec 1st, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. /*Write a program to print the numbers from 1 to 100 on the screen. Skip those numbers which
  2. are divisible by 3 or 5 but not by both. */
  3.  
  4. #include <stdio.h>
  5.  
  6. int main()
  7. {
  8. for(int i = 1; i <= 100; i++)
  9. {
  10. if ((i % 3 == 0 || i % 5 == 0) && !(i % 3 == 0 && i % 5 == 0))
  11. {
  12. continue; // Skip numbers divisible by 3 or 5 but not both
  13. }
  14. printf("%d ", i);
  15. }
  16. printf("\n");
  17.  
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement