First C Program - Hello World

We have gained lots of theoretical knowledge. Now its time to move on and write our first C program and understand it.


Hello World C Program

This is a program to print “Hello World”

#include<stdio.h>

void main()
{
 printf("Hello World");
}


Output
Hello World

Now try to understand this program step by step.

1. #include<stdio.h>: First statement started with #, it is called pre-processor directive. We will learn about them thoroughly in later tutorials. #include<stdio.h> is used to include the stdio.h header file in our program. Header files contains the functions that we use in our program. Here we have used printf() function which is present in stdio.h header file.

2. void main(): Here main() is the function. A program always starts with the main() function and every program must have main(). Here void is the return type of this function. It means main() function will not return anything. The opening curly braces ({) and closing curly braces (}) shows the body of the function.

main() can also be called as a collection of statements.

3. printf(): Here printf() is another function. This is used to print the values on the screen. Its general form is

printf(“Statement you want to print on screen”);

4. Semicolon (;) is used for denoting the termination of statement. It is also called statement terminator in C Language.


How to compile and execute?

Here we are using TURBO C compiler. If you have not downloaded it yet than download it from here.

1. Open Turbo C and type the program.
2. After that press F2 to save the program with .c extension. Eg: program.c
3. Now Press ALT + F9 to compile and CTRL + F9 to run the program.
4. Press ALT + F5 to view the output.

Well this is the easiest C program. Now lets move on and try slightly complicated program of multiplication of two numbers.


C Program to multiply two numbers


#include<stdio.h>

void main()
{
 int a, b, c;
 a=3;
 b=4;
 c=a*b;
 printf("Answer is %d",c);
}

Output
Answer is 12

Now lets try to understand this program.

1. First two statements are same as above program. In the third statement I have written

int a, b, c;

Here int is the keyword for integer and a, b and c are the integer variables. So they can only store integer values.

2. In the next two statements I have written

a=3;
b=4;

In these statements we are storing the values 3 and 4 in a and b variables respectively.

3. In the next statement 

c=a*b;

We are multiplying the values in a and b, and storing them in the variable c.

4. Now in the last statement we are printing the value which is in c. A new thing %d which we have used in this program. It is called format specifier. It usually tell the compiler that it has to print the integer value on screen which is present in a variable.

Some common format specifiers are given below

a. %d for integers
b. %c for characters
c. %f for floating point numbers or real numbers

A bit elaborated form of printf() is given below

printf(“string you want to print ”, variable);

Suppose we have to print the value in b so we will use the function.

printf(“%d”,b);


Things to keep in mind

1. Use semicolon at the end of each statement.
2. Type the statements in main program as the way you want them to be executed.
3. Never try to memorise any program. Just try to understand it.
4. Learning programming is all about practical. So start doing practical from now.

Difference Between Multiprogramming, Multitasking, Multiprocessing and Multithreading

Multiprogramming

Multiprogramming is also the ability of an operating system to execute more than one program on a single processor machine. More than one task/program/job/process can reside into the main memory at one point of time. A computer running excel and firefox browser simultaneously is an example of multiprogramming.

Multiprogramming
Memory layout for Multiprogramming System


Multitasking

Multitasking is the ability of an operating system to execute more than one task simultaneously on a single processor machine. Though we say so but in reality no two tasks on a single processor machine can be executed at the same time. Actually CPU switches from one task to the next task so quickly that appears as if all the tasks are executing at the same time. More than one task/program/job/process can reside into the same CPU at one point of time.


Multitasking
Multitasking System


Multiprocessing

Multiprocessing is the ability of an operating system to execute more than one process simultaneously on a multi processor machine. In this, a computer uses more than one CPU at a time.


Multiprocessing
Multiprocessing System


Multithreading

Multithreading is the ability of an operating system to execute the different parts of a program called threads at the same time. Threads are the light wait processes which are independent part of a process or program. In multithreading system, more than one threads are executed parallely on a single CPU.

Image Credits: TutorialsPoint, National Instruments

Variables, Constants and Keywords in C

Variables in C

In a typical C program we have to do a lot of computation. Of course there will be storing of some data in different locations of memory in computer. These memory locations are identified by their address like 56234. Suppose if programmer wants to access the particular locations like 10 times in a program to store another value at that location. So It will become a tedious job for a programmer if he have to memorise the numerical address name. So to make this job easy we use “Variables”.

So “Variables are nothing but the name of the locations or addresses of memory which is given by programmer.”

Constants in C

As its name suggests constants are the values which will never change during the execution of program.

Sounds confusing? Let’s try to make things more clear with a simple example.
Variables in C
In the above picture (1st) we have stored the constant value 3 at x location. The name of that location is x. It’s a variable. We can also store another value at x location.

Here X = variable (location or memory address name)
3 = constant

Try to understand the second example yourself if you have any doubt, do comment below.

There are two type of Constants

1. Primary constants
2. Secondary constants (We will learn them later)

At this stage we will only discuss primary constants. Primary constants are of three types.

a. Integer constants
b. Real constants
c. Character constants

Let’s discuss them one by one.

Integer Constant

Yes it will contain only integers. Remember an integer constant will never contain any decimal point. Eg: 1, 2, -43 etc

Character Constant

It is single (remember) alphabet, number or any special symbol which is enclosed in an inverted commas. Eg: ’+’, ’1’, ’a’, etc.

Real Constant or Floating Point Constant

A real constant may have any digit but it must contain one decimal point. Eg: 1.22, -54.5, 3432.13

Types of Variables

As I said earlier Variable are name of locations in memory. In that location we can store any constant like integer, character or Real. But there is some limit that an integer variable can only store integer constant, character variable can only store character constant and real variable can only store real constant.

So it is quite obvious types of variables is similar types of constants. Eg: int x= 1;

Here “int” is a keyword, “x” is an integer variable and it can only store integer constant, “1” is a integer constant.

Rules for writing variable names

1. A variable name may contain alphabets, numbers and underscores.
2. No other special character (other than underscore) can be used for writing variable name.
3. A variable name should start with either underscore or alphabets.
4. No space is allowed while writing variables.

Keywords in C

Keywords are the words whose meaning is already explained to the compiler. They cannot be used as a variable name.

A question which may arise in your mind that, how computer will know that its integer variable or character variable or anything else?

The simple answer is with the help of keywords. In one of the above example I have used “int” keyword. Eg: int x=1

In this example “int” is a keyword and it will tell the computer that “x” will be an integer variable and it will only store integer constant.

There are 32 keywords used in C language which are given below. We will discuss them in later tutorials.
Keywords in C
Keywords in C

C Programming Overview

These tutorials are made for those people who have absolutely no pre knowledge of programming. In this tutorial of C programming you will need only a basic knowledge of computers. All the topics are covered from scratch and in the last we will cover some advanced topics too. So let’s get started.

C Programming Overview

What is C language?

Well the answer is quite simple. It’s a procedural programming language which was designed and written by Dennis Ritchie at AT & T’s Bell Labs in 1972. In early 70s very frequently new programming languages were introduced. But after the launch of C, it slowly replaced the old languages like ALGOL. Actually no one advertises this language and even Ritchie was surprised that so many peoples were using C language. Till now many languages has come. But the popularity of C is not changed till now. The main reason behind it is that it is still fast, reliable and easy to use.

C Programming Overview
Ken Thompson and Dennis Ritchie

Why C should be your first programming language?

Seriously many people claim that now one should start its programming journey through C++, C# or JAVA. Well I think nobody will be comfortable while studying the advanced concepts like OOPS from the start.

Compilers

The first question which will arise in our mind. What is a Compiler?
Well as everybody knows Computer is a machine which process raw data into meaningful information. It cannot understand our language. It can only understand machine language. Even if we write programs in any language (like C). At the end they will be converted to machine language to process through computer.

What does Compiler do?

Compiler convert your program into machine language or binary language.

Install IDE first

What is IDE?

IDE means Integrated Development Environment. To write any program in C language you will need an editor. After that to convert that program into machine language, you will need a compiler. IDE will combine editor and compiler into same environment. So that you can easily write the program and also compile it easily.

Well I would suggest you not to use Turbo C. Because it is very old compiler (more than 20 years). Start your C programming journey with some modern compiler like GCC. All programs in our tutorial will run on GCC. Its available free of cost and you can download it from here.

Skip List Data Structure

A skip list is a data structure that is used for storing a sorted list of items with a help of hierarchy of linked lists that connect increasingly sparse subsequences of the items. A skip list allows the process of item look up in efficient manner. The skip list data structure skips over many of the items of the full list in one step, that’s why it is known as skip list.

Skip List Data Structure
Skip List

Complexity


Average Case
Worst Case
Space
O(n)
O(nlogn)
Search
O(logn)
O(n)
Insert
O(logn)
O(n)
Delete
O(logn)
O(n)

Structure of Skip List

A skip list is built up of layers. The lowest layer (i.e. bottom layer) is an ordinary ordered linked list. The higher layers are like ‘express lane’ where the nodes are skipped (observe the figure).

Searching Process

When an element is tried to search, the search begins at the head element of the top list. It proceeds horizontally until the current element is greater than or equal to the target. If current element and target are matched, it means they are equal and search gets finished.

If the current element is greater than target, the search goes on and reaches to the end of the linked list, the procedure is repeated after returning to the previous element and the search reaches to the next lower list (vertically).

Implementation Details

1. The elements used for a skip list can contain more than one pointers since they are allowed to participated in more than one list.

2. Insertion and deletion operations are very similar to corresponding linked list operations.

Insertion in Skip List Data Structure
Insertion in Skip List

Applications of Skip List

1. Skip list are used in distributed applications. In distributed systems, the nodes of skip list represents the computer systems and pointers represent network connection.

2. Skip list are used for implementing highly scalable concurrent priority queues with less lock contention (struggle for having a lock on a data item).

Unrolled Linked List Data Structure

What is Unrolled Linked List?

An Unrolled linked list is a type of link list that stores multiple elements in each node. It is also known as cache sensitive data structure. The term ‘cache’ has been taken from cache memory which is associated with CPU. A cache memory is used to store recently visited pages or data so that they can be made available for RAM immediately without accessing secondary or permanent memory. A typical unrolled linked list can be declared in C as follows.

#define SIZE 50
struct node
{
                int count;            
                int elements[SIZE];
       struct node *next;
};

Each node in the unrolled array contains a certain maximum number of elements. The number of elements are large enough to fill a single cache line. The position of the element in the list can be indicated either by reference or by position in the array. An unrolled linked list can be shown like following.


Unrolled Linked List in Data Structure

The operations those can be performed on an unrolled linked list are insertion and deletion.

Insertion

First of all it is checked if the space is available in the list for inserting a new element. If the space is available, the element is just inserted. When the element is inserted in the array elements, the count variable is incremented by one. If array doesn’t have free space to have an element, we just create a new node, place it after the current node and move half of the elements to newly created node. It creates room/space for the new element.

Deletion

When an element is deleted from the list it is simply removed from the array. If the number of elements in the array falls below N/2, we take the elements from a neighboring array to fill the array. If neighboring array also has N/2 elements then we merge both of the arrays.

Advantages of Unrolled Linked List

1. Due to its cache behavior, the unrolled linked list performs the sequential traversal very rapidly.
2. It requires less storage space.
3. It performs the operations more quickly than ordinary linked list.
4. Indexing time O (N) is reduced to O (N/max), as we are able to process a whole node at a time instead of individual elements.

Disadvantages of Unrolled Linked List

The overhead per node for references and elements count is considerably high.

How to Make a Notepad in VB.Net

In today’s article I am going to provide you a simple notepad source code developed in visual basic.net. So the notepad uses very simple controls like RichTextBox1 and MenuStrips that is used to design the graphical interface. The code is very simple and self explanatory. This notepad has options like File, Edit, Format and Help.

Also Read: How to Create a Web Browser in Visual Basic

How to Make a Notepad in VB.Net

How to Use?


  1. Unzip the rar file we have provided to your favorite folder
  2. Open Visual Studio, go to File > Open > Project/Solution
  3. Navigate to the folder where you have extracted the rar file
  4. Open Notepad.sln file
  5. Now you can make changes in the program

Download the notepad source code from below link.

- Download Notepad Source Code -

C/C++ Program to Find GCD of Two Numbers Using Recursion

In this program we will use recursion and Euclid's algorithm to find greatest common divisor of two numbers. The definition of Euclid's algorithm is as follows:

Also Read: C program to find factorial of any number using recursion
Also Read: How to Convert a Recursive Function or Algorithm to Non-Recursive?



C Program


#include<stdio.h>

int gcd(int n,int m)
{
    if((n>=m)&&((n%m)==0))
        return(m);
    else
        gcd(m,(n%m));
}

int main()
{
    int n,m,result;
    printf("Input the first integer number:");
    scanf("%d",&n);
    printf("Input the second integer number:");
    scanf("%d",&m);
    result=gcd(n,m);
    printf("\nGCD of %d and %d is %d",n,m,result);

    return 0;
}


C++ Program


#include<iostream>
#include<cstdlib>

using namespace std;

int gcd(int n,int m)
{
    if((n>=m)&&((n%m)==0))
        return(m);
    else
        gcd(m,(n%m));
}

int main()
{
    int n,m,result;
    cout<<"Input the first integer number:";
    cin>>n;
    cout<<"Input the second integer number:";
    cin>>m;
    result=gcd(n,m);
    cout<<"\nGCD of "<<n<<" and "<<m<<" is "<<result;

    return 0;
}

C/C++ Program to Find GCD of Two Numbers Using Recursion

PHP Ecommerce Development - All You Need to Know About

Many e-commerce sites feature searching, merchandising and selling of the products online. E-commerce site owners are able to enjoy the downpour of money and advertisements too.

Sites are launched or developed by using PHP scripting language. With a click of a second, there are thousands of schemes and products available at just one stop. Customers intending to search for desired products or have the shipment at their doorsteps can avail hassle free and easy payment gateway by shopping at any e-commerce website.

PHP Ecommerce Development - All You Need to Know About

Owners can build and utilize different e-commerce interfaces as well as provide customized e-commerce solutions to the readers with the help of scripting language known as PHP.


E-commerce is therefore considered as one of the viable options for the people to promote their online business successfully.

Features of PHP Ecommerce Development

The PHP scripting language assisting in the PHP Ecommerce development works on the system of content management. Owing to this features, many site owner are able to have complete control over their website features. Developer can make amazing and customized applications utilizing the PHP features.

PHP Script language can also be embedded into HTML. It works smoothly with Oracles or MySQL open source databases. It aims to provide veritable solutions related to e-commerce development.

The Superior and Efficient performance have made PHP ecommerce development the first choice among many website developers. It enables easy navigation and ecommerce page for customers online. Different packages are available for the website owner depending upon their requirements and future business plans.

As a website owner, you can avail the benefit of high availability and performance towards production. Even the simplest informative sites or the complex social networking and web portals can take advantage of the PHP software.

The PHP development helps in rectifying changes in availability or prices of the products and services too. PHP application is an open source that is available for any platform. For example it can support number of web servers, multiple databases like JAVA, Oracle, MySQL, IMAP and other internet protocols.

Many applications and website developments have now become feasible and easy due to PHP ecommerce development. With the help of PHP ecommerce people are able to make easy transactions. Readers are able to find varied options at one single place.

Advantages of PHP Ecommerce Development Features for the Customers

Customers can easily access owner websites. This tends to directly increase the sales and promotes the online business of the site owners.

Customer can also provide feedback on the purchased products or services.

Customers can save a good time searching for different products at different site by utilizing the benefits of PHP application.

Customers who intend to build or update their websites usually find the PHP technology most convenient and easy to use.

The application of PHP helps the customers and visitors in browsing catalogues with a key name rather than searching for all the items simultaneously.

The customer care forums of PHP application provide equal attention to all the customers.

With the wide publicity and easy accessibility over the internet, people are now developing and promoting more and more individual websites. PHP ecommerce is known as a popular flexible and functional framework utilized by website owners globally for their ecommerce development and solutions.

About Author
Alyisa is a full-fledged, no apologies, and into-the-trenches thrift store warrior. She blogs for stars and other brands she uses. Read her top reviews on topreviewstars.com. She also writes reviews for various companies.

C/C++ Program to Find Substring in String (Pattern Matching)

Pattern matching refers to find the position where a string pattern appears in a given string. If the requird string is not present in given text, then it returns the value zero.

If the required string is present in a given string, it returns the position of occurrence of required string or substring.

Also Read: C program to concatenate two strings without using strcat() function


C Program


#include<stdio.h>

int main()
{
    int i,j,temp;
    char str[100]={"This is a pattern matching"};
    char substr[20]={"pattern"};

    for(i=0;str[i]!='\0';i++)
    {
        j=0;
        if(str[i]==substr[j])
        {
            temp=i+1;
            while(str[i]==substr[j])
            {
                i++;
                j++;
            }

            if(substr[j]=='\0')
            {
                printf("The substring is present in given string at position %d\n",temp);
                exit(0);
            }
            else
            {
                i=temp;
                temp=0;
            }
        }
    }

    if(temp==0)
        printf("The substring is not present in given string\n");

    return 0;
}


C++ Program


#include<iostream>
#include<cstdlib>

using namespace std;

int main()
{
    int i,j,temp;
    char str[100]={"This is a pattern matching"};
    char substr[20]={"pattern"};

    for(i=0;str[i]!='\0';i++)
    {
        j=0;
        if(str[i]==substr[j])
        {
            temp=i+1;
            while(str[i]==substr[j])
            {
                i++;
                j++;
            }

            if(substr[j]=='\0')
            {
                cout<<"The substring is present in given string at position "<<temp<<"\n";
                exit(0);
            }
            else
            {
                i=temp;
                temp=0;
            }
        }
    }

    if(temp==0)
        cout<<"The substring is not present in given string\n";

    return 0;
}

C/C++ Program to Find Substring in String (Pattern Matching)