forked from blau_araujo/cblc
exercícios da aula 9
This commit is contained in:
parent
34efb5e18b
commit
16d98bc911
1 changed files with 102 additions and 0 deletions
102
exercicios/09/README.org
Normal file
102
exercicios/09/README.org
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
#+title: Curso Básico da Linguagem C
|
||||||
|
#+subtitle: Exercícios
|
||||||
|
#+author: Blau Araujo
|
||||||
|
#+startup: show2levels
|
||||||
|
#+options: toc:3
|
||||||
|
|
||||||
|
* Exercícios da aula 9: Argumentos e ambiente
|
||||||
|
|
||||||
|
- [[../../aulas/09-args/README.org][Anotações da aula]]
|
||||||
|
- [[https://youtu.be/uufnW60rg2Q][Vídeo]]
|
||||||
|
|
||||||
|
** 1. Desafio: Programa =listenv=
|
||||||
|
|
||||||
|
Crie um programa que liste as variáveis exportadas para seu ambiente de duas
|
||||||
|
formas:
|
||||||
|
|
||||||
|
*Sem argumentos:* lista todas as variáveis no ambiente...
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
:~$ listenv
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
*Com nomes de variáveis:* lista apenas os valores das variáveis informadas...
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
:~$ listenv VAR1 VAR2 ...
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
Para cada variável inexistente passada como argumento, imprimir na saída
|
||||||
|
padrão de erros (=stderr=)...
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
:~$ listenv SHELL VAR2 VAR3
|
||||||
|
/bin/bash
|
||||||
|
VAR2 não está definida no ambiente
|
||||||
|
VAR3 não está definida no ambiente
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
** 2. Desafio: Programa =tconv=
|
||||||
|
|
||||||
|
Crie um programa que converta temperaturas segundo a sintaxe abaixo:
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
tconv 23.4c Converte 23.4 graus Celsius para Fahrenheit
|
||||||
|
tconv 100f Converte 100 graus Fahrenheit para Celsius
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
A unidade deve ser indiferente à caixa de texto (~f = F~, ~c = C~).
|
||||||
|
#+end_quote
|
||||||
|
|
||||||
|
** 3. Desafio: Programa =2fer=
|
||||||
|
|
||||||
|
Crie um programa que, para cada =NOME= recebido como argumento, imprima:
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
Um para NOME, um para mim.
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
Se nenhum nome for passado, imprimir:
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
Um para você, um para mim.
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
** 4. Desafio: Programa =fatp=
|
||||||
|
|
||||||
|
Escreva um programa que imprima os fatores primos de um número inteiro positivo
|
||||||
|
maior do que 1 recebido como argumento.
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
:~$ fatp 90
|
||||||
|
2 3 3 5
|
||||||
|
:~$ fatp 36
|
||||||
|
2 2 3 3
|
||||||
|
:~$ fatp 43
|
||||||
|
43 é primo!
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
|
||||||
|
** 5. Desafio: Programa =round=
|
||||||
|
|
||||||
|
Escreva um programa que, recebendo um número com ponto flutuante como argumento,
|
||||||
|
faça o seu arredondamento das seguintes formas:
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
:~$ round 2.5
|
||||||
|
3
|
||||||
|
:~$ round 2.4
|
||||||
|
2
|
||||||
|
:~$ round -c 2.3
|
||||||
|
3
|
||||||
|
:~$ round -f 2.9
|
||||||
|
2
|
||||||
|
:~$ round -t 2.6
|
||||||
|
2
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
#+begin_quote
|
||||||
|
As opções =-t= (/truncate/), =-f= (/floor/) e =-c= (/ceil/) podem ser escritos antes ou
|
||||||
|
depois do número. As opções =-t= e =-f= são sinônimas.
|
||||||
|
#+end_quote
|
Loading…
Add table
Reference in a new issue