Skip to content

Instantly share code, notes, and snippets.

@fabiommendes
Created October 6, 2021 14:28
Show Gist options
  • Save fabiommendes/5aa4af6ae551c7eb0c758c22488be078 to your computer and use it in GitHub Desktop.
Save fabiommendes/5aa4af6ae551c7eb0c758c22488be078 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
double PI = 3.14;
int fat(int n) {
if (n == 0) {
return 1;
}
else {
return n * fat(n - 1);
}
}
void print_collatz(int n) {
while (n != 1) {
printf("%d\n", n);
if (n % 2 == 0) {
n = n / 2;
}
else {
n = 3 * n + 1;
}
}
printf("%d\n", n);
}
void print_fibo(int n) {
int x = 1, y = 1, aux;
for (int i = 0; i < n; i++) {
printf("%d) %d\n", i, x);
aux = x;
x = y;
y = aux + y;
}
}
int next_collatz(int n) {
if (n % 2 == 0) {
return n / 2;
}
else if (n == 1) {
return 1;
}
else {
return 3 * n + 1;
}
}
int main() {
int n;
printf("n: ");
scanf("%d", &n);
printf("FizzBuzz de 1 até %d\n", n);
// ... implemente o fizzbuzz usando o for!
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment