A solution to a problem is clearly defined in pseudocode the programmer can focus on the syntax and semantics of the Programming Language.
e.g. Euclid Algorithm
- Input a, b
- Initalize the value of x to a and the value of y to b
- If x>y then set x to x-y
- If x<y then set y to y-x
- Repeat steps 3 and 4 until x=y
- Output x (or y) and halt.
C program main(){ int a, b, x, y; scanf("%d%d", &a,&b); x=a; y=b; do{ if(x>y) x=x-y; else if(x<y) y=y-x; }while(x!=y); printf("gcd=%d\n", x); }As with the above example the Greatest Common Denominator can be found. They both relate perform the same operations. The major difference is the syntax and that the c program will compile.
No comments:
Post a Comment