C Language | Prime Numbers

Thursday, 6 December 2012

In numbers, there are those that can be divided with different other integers and those that are only limited to the integer itself and number one (1). That kind of numbers are known as the Prime Numbers. Prime numbers can only be divided by the number one (1) or the prime number itself.

Sometimes, it can be difficult for us to recognize prime numbers specially when the numbers are large. That's why I made a program that evaluates a number and tells us if the number is a prime number or not. In this program, I used looping statements and If else statements to make the program more stable. Check out the sample code below.

     1:  
   2:  #include<stdio.h>
   3:  #include<conio.h>
   4:   
   5:  main()
   6:  {
   7:        int input, num=0, div, count, count2,x;
   8:        printf("Enter how many counts: ");
   9:        scanf("%d",&count);
  10:        
  11:        if(count>3000){
  12:        printf("You have exceeded the maximum input of 3000");
  13:        getch();
  14:        return 0;
  15:        }

C Language | For Loop Statement

Wednesday, 5 December 2012


After I showed you how the Do-While Loop executes, I will now show you the second looping statement which is more easier to use, the For Loop. For Loop repetition statement is a one line argument. It holds the control variable, condition and the increment of control variable in one line/argument, which makes it more easy. For Loop is used on most programs because it helps a lot in making a program short and straight.

Now, I made a sample program to show you how the for loop works. The sample I made is the same example I had in the do-while loop. I just changed it to for loop statement. In this example, you will observe the difference between the do-while and for loop statements and how the codes are arranged. Check out the codes below.

     1:  
   2:  #include <stdio.h>
   3:  #include <conio.h>
   4:   
   5:  int main()
   6:  {
   7:  int n;
   8:  int value = 1;

C Language | Do-While Loop Statement


From my previous codes, we encountered looping statements that helped us with the repetitive parts of the program. Now, I will introduce you the two looping statements that is very useful in program control. These looping statements are the Do-While Loop and For Loop.

Now, I will show you the Do-While Loop. Do-While Loop processes the statement once before processing the condition. Do-While loop is used on programs that statements are needed to be executed first before processing the condition. To show you how the do-while loop work, I made a simple program that will execute it. Check out the codes below.

     1:  
   2:  #include <stdio.h>
   3:  #include <conio.h>
   4:   
   5:  int main()
   6:  {
   7:  int n;
   8:  int generate = 1;
   9:   
  10:  printf("Enter number: ");
  11:  scanf("%d", &n);
  12:   
  13:  do
  14:  {

C Language | Subtraction


On my previous topic, I was sharing about basic mathematics. I already show you how to add two integers and how to add a couple of integers being manipulated through your inputs and looping statements. Now, basic mathematics will not be complete without subtraction. Subtraction is the process of taking out certain amount from another amount. To understand more of this process I made a program that subtracts numbers. It also acts like a calculator.

This program, like the previous addition program I made, is used with a data type int because we're using integers, which needs to be whole numbers as inputs. Check out the codes below.


     1:  
   2:  #include<stdio.h>
   3:  #include<conio.h>
   4:   
   5:  int main()
   6:  {
   7:  int a,b,c;
   8:   
   9:  printf("Enter number: ");
  10:  scanf("%d", &a);
  11:   
  12:  printf("\nEnter number: ");

C Language | Addition part 2


Last time, I showed you how to create a simple addition program using C language. Now, we will still be adding numbers but I put something new in it. Yes, we will still add integers/numbers but it is now in the users decision how many integers he will add.

We will still use int as our data identifier because we are still inputting integers. The new command we're going to put into the code is the for loop statement. This statement will control how many inputs a user want. From the name itself, loop, it means infinity. For loop is a repetitive statement, the program will not stop/end until the argument inside the loop is met. This statement is useful when you have to make repetitive programs because this will excuse you from doing the same code again and again.

The program you see below is an example of adding numbers but inputs can be manipulated by the user. Check out the codes below.


   1:   
   2:   
   3:   
   4:  #include <stdio.h>
   5:  #include <conio.h>
   6:   
   7:  int main()
   8:  {
   9:      int a, b = 0, c = 1, sum = 0;
  10:   
  11:      printf("How many numbers you want to add?: ");
  12:      scanf("%d", &a);

C Language | Addition part 1

Wherever we went we always encounter math, either when you're at home, in school or even in the market. Most of time, basic mathematics is always useful like addition and subtraction. Before, adding or subtracting is used with beads or stones or whatever things that might represent the figure all of it can be useful. Then, new generation has come and calculators were born. Today, computers are used. So, I thought of making a program that can add numbers just like a calculator using C language.

The program is designed to add two (2) numbers/integers using the basic mathematics and C language commands. Check out the codes below.



     #include<stdio.h>
     #include<conio.h>
     
     int main()
    {
     int a,b,c;
     
     printf("Enter number: ");
     scanf("%d", &a);
     
     printf("\nEnter number: ");
     scanf("%d", &b);
    
     c = a + b;
    
     printf("\nThe sum is %d", c);
     getch();
     }

C Language | Hello World a start with programming

Monday, 3 December 2012

C language is a basic programming language used to create simple to complex programs. C has different kinds of commands such as pre-processors, arrays, strings, if else statements and switch case statements. During my first lecture in this subject, programming, my professor introduce to us C language using the well known Hello World program. So, to introduce to you C language I will show you the Hello World program.

In this program, we used simple codes. We have there the pre-processor command which is the #include and the header files stdio.h and conio.h. There is also our command for output which is the printf. Lastly, to terminate the program getch(); is the key for that. It prompts user to input any character that will not show but rather to terminate the program. Check out the codes below.


   1:  #include <stdio.h>
   2:  #include <conio.h>
   3:   
   4:  int main()
   5:  {
   6:  printf("Hello World!");
   7:  getch();
   8:  }

Related Posts Plugin for WordPress, Blogger...