Guest User

Untitled

a guest
Jan 12th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void){
  4.  
  5. // Example 2: conditional structures.
  6.  
  7. int answer = 42;
  8.  
  9. if (answer == 42) //Only runs the line below if true
  10. printf("You have found the answer! It is %d\n\n", answer);
  11.  
  12. else // Only runs the line below if false
  13. printf("WRONG!!!!");
  14.  
  15. //----------------------------------
  16.  
  17. // Example 2: conditional structures
  18.  
  19. // Notice the next conditional has curly brackets
  20. // between the execution blocks.
  21. // This is because multiline blocks of code need to be wrapped
  22. // while a single line statment does not require the curly brackets
  23.  
  24.  
  25. if (0){
  26. printf("one\n");
  27. printf("two\n");
  28. }
  29. else if(1){
  30. printf("three\n");
  31. printf("four\n");
  32. }
  33. else{
  34. printf("no more numbers!");
  35. }
  36. }
Add Comment
Please, Sign In to add comment