The first step is to understand the problem of what you are trying to solve. Then break that problem into smaller problems. Then solve each smaller problem.
As for writing code, follow the ABCs, Always Be Cleaning. Meaning always keep your code clean and readable. Readable as in someone from the street knows what such and such variable is used for. In the long run it will save you a lot of time. Use symbols and words that make sense, for example, if you are writing a program that uses the "Equation of a Straight Line," then use the standard notation y=mx+b and not something crazy like g=rl+a.
For writing actual code, be consistent in your spacing and usage of brackets, like the following.
Code:
#include <stdio.h>
int main()
{
int a=1;
int b=2;
int c=3;
if ( c < b )
{
printf("C is greater than B!\n");
if ( a < b )
{
printf("A is less than B!\n");
}
}
printf("Hellow World!\n);
return 0;
}
As you can see, it is easy to read and there is no question as to what is happening. The above code could have been written as
Code:
#include <stdio.h> int main() { int a=1; int b=2; int c=3; if ( c < b ) { printf("C is greater than B!\n"); if ( a < b ) { printf("A is less than B!\n"); } } printf("Hellow World!\n); return 0; }
But it is harder to read and understand, and I can promise you if you write code like the above, other programmers will want to hurt you in a bad way.