Advertisement
michael_xgrind

Untitled

Aug 28th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3.  
  4. main() {
  5.     int num1, num2, total = 0;
  6.  
  7.     printf("Entre com o numero 1: ");
  8.     scanf("%d", &num1);
  9.     printf("Entre com o numero 2: ");
  10.     scanf("%d", &num2);
  11.  
  12.     total = num1+num2;
  13.  
  14.     /* usando if */
  15.     /* ele testa ate encontrar o valor */
  16.  
  17.     printf("\nUSANDO IF");
  18.     if (total==1) {
  19.         printf("\nTotal: %d\n", total);
  20.     }
  21.     else {
  22.         if (total==2) {
  23.             printf("\nTotal: %d\n", total);
  24.         }
  25.         else {
  26.             if (total==3) {
  27.                 printf("\nTotal: %d\n", total);
  28.             }
  29.             else {
  30.                 if (total==4) {
  31.                     printf("\nTotal: %d\n", total);
  32.                 }
  33.                 else {
  34.                     printf("\nTotal: %d\n", total);
  35.                 }
  36.             }
  37.         }
  38.     }
  39.  
  40.     /* usando switch case */
  41.     /* ele vai direto no resultado. nao faz testes */
  42.  
  43.     printf("\nUSANDO SWITH CASE");
  44.     switch (total) {
  45.         case 1:
  46.             printf("\nTotal: %d", total);
  47.             break;
  48.         case 2:
  49.             printf("\nTotal: %d", total);
  50.             break;
  51.         case 3:
  52.             printf("\nTotal: %d", total);
  53.             break;
  54.         case 4:
  55.             printf("\nTotal: %d", total);
  56.             break;
  57.         case 5:
  58.             printf("\nTotal: %d", total);
  59.             break;
  60.     }
  61.  
  62.  
  63.     #ifdef __WIN32__
  64.     system("pause");
  65.     #endif // __WIN32__
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement