printf("Digite um número impar:\n");
scanf("%d", &numero);
if (numero % 2 == 0) {
return -1; // Número é par :(
}
// Continuo meu programaImaginem o seguinte programa:
printf("Digite um número impar:\n");
scanf("%d", &numero);
if (numero % 2 == 0) {
printf("Digite um número impar:\n");
scanf("%d", &numero);
if (numero % 2 == 0) {
printf("Digite um número impar:\n");
scanf("%d", &numero);
if (numero % 2 == 0) {
// ...
}
}
}
// Continuo meu programa
Esse programa deve ter as seguintes funcionalidades:
printf("1 - Logar no Twitter \n");
printf("2 - Twittar \n");
printf("3 - Ver meus últimos 5 tweets \n");
printf("0 - Sair do programa\n");
scanf("%d", &opcao);
if (opcao == 1) {
// ....
}
else if (opcao == 2) {
// ...
}
else if (opcao == 3) {
// ...
}
else if (opcao == 0) {
// ...
}sair = 0;
while (!sair) {
printf("1 - Logar no Twitter \n");
printf("2 - Twittar \n");
printf("3 - Ver meus últimos 5 tweets \n");
printf("0 - Sair do programa\n");
scanf("%d", &opcao);
if (opcao == 1) {
// ....
}
else if (opcao == 2) {
// ...
}
else if (opcao == 3) {
// ...
}
else if (opcao == 0) {
sair = 1;
}
}do {
printf("Digite um número impar:\n");
scanf("%d", &numero)
} while (numero % 2 == 0)Utilizar a função buscar_tweet(n_tweet) para buscar os últimos 5 tweets e imprir na tela.
Essa função recebe como parâmetro o número do tweet e retorna o texto do tweet.
Suponhamos que o último tweet é o número 1, o penúltimo o número 2, o antepenúltimo 3, etc ...
numero_tweet = 1;
while (numero_tweet <= 5) {
tweet = buscar_tweet(numero_tweet);
printf("TWEET: %s \n", tweet);
numero_tweet = numero_tweet + 1;
}numero_tweet = 1;
while (numero_tweet <= 5) {
tweet = buscar_tweet(numero_tweet);
printf("TWEET: %s \n", tweet);
numero_tweet = numero_tweet + 1;
}O meu loop while está funcionando com uma variável contadora (numero_tweet), ou seja, enquanto numero_tweet for menor ou igual a 5 é executado o código dentro do loop, e no final do loop numero_tweet é incrementado em 1.
// INICIALIZAÇÃO
numero_tweet = 1;
// CONDIÇÃO
while (numero_tweet <= 5) {
tweet = buscar_tweet(numero_tweet);
printf("TWEET: %s \n", tweet);
// INCREMENTO
numero_tweet = numero_tweet + 1;
}
// INICIALIZAÇÃO; CONDIÇÃO; INCREMENTO
for (numero_tweet = 1; numero_tweet <= 5; numero_tweet++) {
tweet = buscar_tweet(numero_tweet);
printf("TWEET: %s \n", tweet);
}