Subscribe Twitter FaceBook

Sabtu, 26 Juni 2010

Algorithm and Programming part 2

Algorithm in C has 3 main parts :
1.  Header
2.  Declaration
3.  Description

>>Header means library on C system that you want to use in creating program
>>Declaration means place where you can declare or define constanta , variable, function, & etc..
>>Description means place for main statements in program

here is sample for odd and even number


#include
int main()  //this is header
{
int a,b;  //this is declaration

//this below statements are description
printf("input a number :");scanf("%d", &a);
b=a%2;
if (b==0)
printf("the number is even \n");
else
printf("the number is odd \n");
}
save by name number.c

Algorithm and Programming part 1

In this Occasion, I wanna share about Algorithm and Programming .  What is Algorithm ??? Algorithm is Sequence of command or Process .  Programming is a process to make program.  Okay,  In this case i'm gonna gonna share by using C language programming
Why do i choose C programming language ??? Because C is the oldest and the most famous programming language
Here is the requirements for good algorithm :
1.  Every step must be absolute
2.  At least 1 output
3.  Systematic
4.  Having term to stop process

This is a sample for 1st Program
#include
void main(){
  printf("hello world \n");
}

save by name hello.c
compile by using this command
#gcc hello.c -o hello
run by using this command
#./hello

This is a sample for 2nd Program


#include
const phi=3.14;
int main(){
int r;
float l,k;
printf("input ring finger :");scanf("%d", &r);
l=phi*r*r;
k=2*phi*r;
printf("circumference is : %2f \n", k);
printf("wide circle is      :%2f \n", l);
}
save by name circle.c

see you later on 2nd part