Skip to content

Instantly share code, notes, and snippets.

@sazid
Last active April 18, 2017 14:39
Show Gist options
  • Save sazid/cfc01552604ce00468a5f4d9fce8dae1 to your computer and use it in GitHub Desktop.
Save sazid/cfc01552604ce00468a5f4d9fce8dae1 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int maxIdx(int x[], int size) {
int i;
int m = x[0];
int idx = 0;
for (i = 0; i < size; i++) {
if (m < x[i]) {
m = x[i];
idx = i;
}
}
return idx;
}
int fibo(int n) {
if (n == 0) return 0;
else if (n == 1) return 1;
return fibo(n - 2) + fibo(n - 1);
}
void split_1(int n) {
while (n > 0) {
printf("%d ", n % 10);
n = n / 10;
}
}
void split_2(int n) {
if (n == 0) return;
printf("%d ", n % 10);
return split_2(n / 10);
}
int main() {
int n[5] = {22, 38, 8, 0, 8};
printf("max index: %d\n", maxIdx(n, 5));
printf("fibonacci: %d\n", fibo(6));
printf("\n");
split_1(3712);
printf("\n");
split_2(3712);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment