Oct 12, 2012

Introducing long

Long is a type of data that allows a plenty of numbers, if you need to show too much numbers, here's your type. By the way, signed and unsigned not work for long. Unsigned int is the same memory space for long, so use it as you want.

#include <stdio.h>

main()
{
      long st, nd;
     
      printf("Enter the first number ");
      scanf("%d", &st);
      printf("Enter the second number ");
      scanf("%d", &nd);
      printf("The result is %d", st * nd);
      getchar();
      getchar();
      getchar();
}

Introducing unsigned and signed

Just looking the signed and unsigned instructions, to be simple, unsigned is for numbers that are positive ONLY, and the signed is for negative numbers. This instructions goes before the data type, example, unsigned int. Here's an example code.

#include <stdio.h>

main()
{
      int st;
      signed int nd;
      unsigned int rd;
     
      st = -1;
      nd = -2;
      rd = 3;
     
      printf("The first number is %d", st);
      getchar();
      printf("The second number is %d", nd);
      getchar();
      printf("The third number is %d", rd);
      getchar();
}

Using formulas and multiplicating with variables

 The program will ask you for the numbers and show the result, for my opinion, I'll put a clrscr(); under the first getchar();. I have to learn the pow instruction, I knew how to do this without the math.h header but I lost that code. Nevermind, enjoy the program.

#include <stdio.h>

main()
{
      int a, b, st_rslt, nd_rslt;
      printf("Enter the first number ");
      scanf("%d", &a);
      printf("Enter the second number ");
      getchar();
      scanf("%d", &b);
      st_rslt = (a+b)*(a-b);
      nd_rslt = (a * a) - (b * b);
      printf("The result of the (a+b)*(a-b) formula is %d", st_rslt);
      getchar();
      getchar();
      printf("The result of the a^2-b^2 formula is %d", nd_rslt);
      getchar();
}

Mnd is learning Java!

Yeah, I know. I got "afk" for three days but I'm back, I'll post that three codes that I got to post, sorry, blame my god-dammed exams.
Now I'm trying to learn Java for Android development so, when I do my first program, I'll upload a .zip with the entire project, I use Eclipse IDE.
I've done a "Hello, World" Android app (it's so easy, just do a new project and Eclipse creates a project with "Hello, world!" code by default) but there's too, TOO MUCH to learn.
So stay tuned!

Oct 9, 2012

Introducing scanf

scanf is an instruction that saves a number or value in a variable, is used after a printf. This time I'll use it for sum two numbers, the program will ask for that numbers and then show the result.

#include <stdio.h>

main()
{
      int st_num;
      int nd_num;
      int rslt;
     
      printf("Enter the first number right here ---> ");
      scanf ("%d", &st_num);
      printf("Enter the second number right here --> ");
      scanf ("%d", &nd_num);
      rslt = st_num + nd_num;
      printf("Your result is %d", rslt);
      getchar();
      getchar();
}

Oct 8, 2012

Sum of two numbers with variables, short version.

Same as the last post, a simple sum with variables entered by the user in the code, the program will not ask for them in the time you run the program. Thsi time is in short code version, but it does the same.

#include <stdio.h>

main()
{
      int firstNumber = 234;
      int secondNumber = 567;
      int addition;
     
      addition = firstNumber + secondNumber;
      printf("Your addition is %d", addition);
      getchar();
}

Oct 7, 2012

Addition of two variables

Same as the last sum/addition post, but I introduce variables. The variables are entered in the code, the program will not ask for them. Then the program work with the numbers and show the result.

#include <stdio.h>

main()
{
      int firstNumber;
      int secondNumber;
      int addition;
     
      firstNumber = 234;
      secondNumber = 567;
      addition = firstNumber + secondNumber;
      printf("Your addition is %d", addition);
      getchar();
}

Sum/Adittion of two numbers

Simple code, just a sum of two numbers entered in the code, the program will show the result only, will not ask the numbers.

#include <stdio.h>

main()
{
      printf("The addition of 3 and 4 is %d", 3+4);
      getchar();
}

Hello, world!

A simple showing message program used to teach programming languages, this will be the first program you learn.

#include <stdio.h>

main()
{
      printf("Hello, world!");
      getchar();
}