Advertisement
leohgoes

Untitled

Mar 26th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.54 KB | None | 0 0
  1. #define ex3
  2. #include "stdio.h"
  3.  
  4. #ifdef ex1
  5.  
  6. /*
  7. 1  - C
  8. 2  - E
  9. 3  - E
  10. 4  - C
  11. 5  - E
  12. 6  - E
  13. 7  - E
  14. 8  - E
  15. 9  - E
  16. 10 - E
  17. */
  18.  
  19. main(){
  20.     int num1, num2, and, or, xor;
  21.     puts("execute as operações lógicas AND, OR e XOR usando atribuição composta");
  22.     printf("Digite o 1 numero");
  23.     scanf("%d", &num1),
  24.     printf("Digite o 2 numero");
  25.     scanf("%d", &num2);
  26.  
  27.     and = or = xor = num1;
  28.     and &= num2;
  29.     or  |= num2;
  30.     xor ^= num2;
  31.  
  32.     printf("    decimal - hex");
  33.     printf("\nAND %d %d", and, and);
  34.     printf("\nOR  %d %d", or, or);
  35.     printf("\nXOR %d %d", xor, xor);
  36. }
  37.  
  38. #endif
  39.  
  40. #ifdef ex2
  41.  
  42. main(){
  43.     char resp;
  44.     int ini = 150;
  45.     int med;
  46.     int fim = 250;
  47.  
  48.     printf("Pense entre um número entre 150 e 250 \n");
  49.  
  50.     for(;;)
  51.     {
  52.         med = ini + ((fim - ini) / 2);
  53.         printf("O numero pensado e' >, < ou = a %d?", med);
  54.  
  55.         scanf("%c", &resp);
  56.         getchar();
  57.  
  58.         if(resp == '=')
  59.         {
  60.             printf("parabens\n");
  61.             break;
  62.         }
  63.         else if(resp == '>')
  64.         {
  65.             ini = med;
  66.         }
  67.         else if(resp == '<')
  68.         {
  69.             fim = med;
  70.         }
  71.     }
  72.     printf("O numero que vc pensou foi %d", med);
  73. }
  74.  
  75. #endif
  76.  
  77. #ifdef ex3
  78.  
  79. // não entendi o que é pra fazer
  80.  
  81. int vet1[2][3] = {{0,0}, {0,0}, {0,0}};
  82. int vet2[2][3] = {{0,0}, {0,0}, {0,0}};
  83.  
  84. main(){
  85.     int x, y;
  86.     printf("vet1\n");
  87.     for(x = 0; x < 2; x++)
  88.         for(y = 0; y < 3; y++)
  89.             scanf("%d", &vet1[x][y]);
  90.     printf("vet2\n");
  91.     for(x = 0; x < 2; x++)
  92.         for(y = 0; y < 3; y++)
  93.             scanf("%d", &vet2[x][y]);
  94.     printf("Resultados\n");
  95.     for(x = 0; x < 2; x++)
  96.         for(y = 0; y < 3; y++)
  97.             printf("\nSoma de vet1(%d,%d) e vet2(%d,%d) = %d",x ,y, x, y, vet1[x][y] + vet2[x][y]);
  98.     for(x = 0; x < 2; x++)
  99.         for(y = 0; y < 3; y++)
  100.             printf("\nSubtração de vet1(%d,%d) e vet2(%d,%d) = %d",x ,y, x, y, vet1[x][y] - vet2[x][y]);
  101.     for(x = 0; x < 2; x++)
  102.         for(y = 0; y < 3; y++)
  103.             printf("\nMultiplicação de vet1(%d,%d) e vet2(%d,%d) = %d",x ,y, x, y, vet1[x][y] * vet2[x][y]);
  104.     for(x = 0; x < 2; x++)
  105.         for(y = 0; y < 3; y++)
  106.             printf("\nDivisão de vet1(%d,%d) e vet2(%d,%d) = %d",x ,y, x, y, vet1[x][y] / vet2[x][y]);
  107. }
  108.  
  109. #endif
  110.  
  111. #ifdef ex4
  112.  
  113. struct string{
  114.     char string1[6];
  115.     unsigned u;
  116.     long l;
  117.     char string2[10];
  118.     double d;
  119. };
  120.  
  121. main(){
  122.     struct string laranja;
  123.  
  124.     printf("Entre a string1 (ate 5 char): ");
  125.     scanf("%s", &laranja.string1);
  126.     printf("Entre o unsigned: ");
  127.     scanf("%u", &laranja.u);
  128.     printf("Entre o long: ");
  129.     scanf("%ld", &laranja.l);
  130.     printf("Entre a string2 (ate 9 char): ");
  131.     scanf("%s", &laranja.string2);
  132.     printf("Entre o double: ");
  133.     scanf("%lf", &laranja.d);
  134.  
  135.     printf("        10        20        30        40        50        60        70");
  136.     printf("\n1234567890123456789012345678901234567890123456789012345678901234567890");
  137.  
  138.     printf("\n%-5s", laranja.string1);
  139.     printf("   %-9s", laranja.string2);
  140.     printf("                          %-9.1lf", laranja.d);
  141.     printf("\n%-5u", laranja.u);
  142.     printf("                                   %-11ld", laranja.l);
  143. }
  144.  
  145. #endif
  146.  
  147. #ifdef ex5
  148.  
  149. main(){
  150.     float media, cont, valor;
  151.     media = 0;
  152.     cont = 0;
  153.     do{
  154.         printf("Digite um numero inteiro positivo. Para terminar digite zero: ");
  155.         scanf("%f", &valor);
  156.         if(valor > 0){
  157.             cont = cont + 1;
  158.             media += valor;
  159.         }
  160.     }while(valor != 0);
  161.     printf("\n\nForam digitados %.0f numeros positivos", cont);
  162.     printf("\n\nA media dos valores digitados e': %.2f", (media / cont));
  163. }
  164.  
  165. #endif
  166.  
  167. #ifdef ex6
  168.  
  169. main(){
  170.     float a, b;
  171.     char op;
  172.  
  173.     printf("entre com um numero: ");
  174.     scanf("%f", &a);
  175.  
  176.     for(;;){
  177.         printf("entre com um numero: ");
  178.         scanf("%f", &b);
  179.         getchar();
  180.  
  181.         printf("entre o sinal da operação (= para terminar): ");
  182.         scanf("%c", &op);
  183.  
  184.         if(op == '=')
  185.             break;
  186.  
  187.         switch(op){
  188.         case '+':
  189.             printf("soma %f\n", a += b);
  190.             break;
  191.         case '-':
  192.             printf("sub %f \n", a -= b);
  193.             break;
  194.         case '*':
  195.             printf("mult %f \n", a *= b);
  196.             break;
  197.         case '/':
  198.             printf("div %f \n", a /= b);
  199.             break;
  200.         }
  201.         printf("O resultado final do calculo e': %f", a);
  202.     }
  203. }
  204.  
  205. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement