Programming C “Mathematic Is Easy” is talk about some numbers.  In this program I use program language C with Visual Studio 2012. In this program include, operator, variable, array, flow control, array and recursive.

This program has 5 menu :

1. Fibonacci

2. Factorial

3. Even number and odd number

4. Hanoi Tower

5. Sorting Number

Flow chart this program :

mathok

Source code program :


#include<stdio.h>
#include<stdlib.h>

int Fibonacci(int k);
int faktorial(int k);
int genap(int n);
int ganjil(int m);
void hanoi(int n, char x, char y, char z);
void swapValue(int *tIntA, int *tIntB);
int main(void){
int choice;
int k, BS;
int genap(int n);
int ganjil(int m);
int m;
int Fibonacci(int k);
int tListAngka[1000];
int tSwap;
int tUrutan;
int tmasuk;

printf("-----------------------------------------------------------------------------\n");
printf("                                Welcome to Application                       \n\n");
printf("                                  Mathematic Is Easy                         \n\n");
printf("-----------------------------------------------------------------------------\n");
printf("                           - Created By Rizki Syaputra -                     \n");
printf("\n\n");
printf("\nMenu : \n");
printf("1. Fibonacci \n");
printf("2. Factorial \n");
printf("3. Even Number and Odd Number\n");
printf("4. Hanoi Tower \n");
printf("5. Sorting Number\n");
printf("\n\n");
printf("Please choice menu do you want (1...5) > ");
scanf("%d",&choice);
printf("\n\n");
switch (choice)
{
case 1:
printf("                 Fibonacci                      \n");
printf("------------------------------------------------\n");
printf("Please insert number  >");
scanf("%d",&m);
printf("\n");
printf("\nWith recursif calculation, number -  %d from fibonacci series is  %d\n",m, Fibonacci(m));
system("pause");
return 0;
break;
case 2:
printf("               Factorial                       \n");
printf("-----------------------------------------------\n");
//int m;
// int faktorial(int k);

printf("Please input number  >");
scanf("%d",&m);
printf("\nWith recursif calculation,  %d != %d\n",m, faktorial(m));
system("pause");
return 0;
break;
case 3:
printf("          Even and Odd Number                   \n");
printf("------------------------------------------------\n");
printf("Please input number  >");
scanf("%d",&k);
if(k==0){
printf("\nZero is not even number and odd number.\n");
}else
{
BS = genap(k);
if(BS==1)
printf("\nNumber  %d is Even number.\n",k);
else if(BS==0)
printf("\nNumber  %d is Odd number.\n",k);
}
system("pause");
return 0;
break;
case 4 :
printf("           Hanoi Tower                            \n");
printf("Please input total disk  > ");
scanf("%d",&m);

printf("Step by step for move disk : \n");
hanoi(m,'1','2','3');
system("pause");
return(0);
break;
case 5:
printf("                    Sorting Number                    \n");
printf("Please input how many number will sorting  : \n");
scanf("%d",&tmasuk);

for(tUrutan=0; tUrutan<tmasuk; tUrutan++){
printf("Value number -  %d  : ", tUrutan);
scanf("%d",&tListAngka[tUrutan]);
}

do{
tSwap =0;
for(tUrutan =0; tUrutan <tmasuk; tUrutan++){
if(tListAngka[tUrutan]<tListAngka[tUrutan+1]){
swapValue(&tListAngka[tUrutan],&tListAngka[tUrutan+1]);
tSwap=1;
}

}

}while (tSwap==1);
printf("\n\n");
printf("Number after sorting : \n");
for(tUrutan=0; tUrutan<tmasuk; tUrutan++){
printf("Value  : %d,\n", tListAngka[tUrutan]);

}
system("pause");
return(0);
break;
default:
printf("please input number 1...5 \n");
system("pause");
break;

}
}

int Fibonacci(int k){
int Fib=1;
if(k>2){
Fib = Fibonacci (k-1)+Fibonacci(k-2);
return Fib;
}else{
return Fib;
}

}

int faktorial(int k){

if(k==0)
return 1;
else
return k*faktorial(k-1);

}

int genap(int n){
if(n==0)
return 1;
else
return ganjil(abs(n)-1);

}

int ganjil(int m){
if(m==0)
return 0;
else
return genap(abs(m-1));
}

void hanoi(int n, char x, char y, char z){
if(n==1)
printf("Move disk from the heighest pole %c to pole %c \n",x,y);
else
{
hanoi(n-1,x,z,y);
hanoi(1,x,y,z);
hanoi(n-1,y,x,z);
}
}

void swapValue(int *tIntA, int *tIntB){
int tInt=*tIntA;
*tIntA= *tIntB;
*tIntB=tInt;
}

Link Video di Youtube :