Thursday 16 August 2012

Math, Array, Matrix & String Manipulation

Introduction - 

This post has been specially designed for students who want to study something about Maths, Arrays, Matrix and String Manipulation using C language. 

For this purpose we are going to design a Menu Based System which is going to offer users some choices from which the user will select the desired operation and will provide the details and will start using the system.



Making Menu - 
The first thing that we are going to do is to make a Menu, before that you must make a project in Visual Studio 2010 or 2008. If you don't know how to make a project in Visual Studio visit this post ..

Considering you had made a project in Visual Studio 2010/2008 lets start with the coding part....

Step 1 : Include the Header Files...For this point in time we will include only one Header File #include<stdio.h>

Header Files are also known as Preprocessor Directives in which standard input/output functions are defined.

Step 2 : Make a Main Function like this give below...

int main()
{

}

One thing that you must understand about main function is that it is the part of the program from where the program execution starts. Don't worry about the body we will do that later on in this post. For this time make a Main function.

Step 3 : Its time to write the name of the system so that it might look like this -

Its completely your choice what name you want to give to the system. For Example - 
  • C Manipulation
  • Assignment by "Your Name"
  • etc
For this purpose we will use a printf() statement -

            printf("Math, Array, Matrix & String Manipulation");

This printf() statement would be written in the main function. printf() statement is used to print something on the console application. Console is where you output would be displayed. So, its time to check how the header looks but before that write two statements after this printf() statement in main function...

getch();

return 0;

We will discuss both the statements later on. For this moment in time your code should look like this....

int main()
{
    printf(" ___  Math, Array, Matrix & String Manipulation  ___");
    
    getch();
   
    return 0;
}

Run the program.. For this either press F5 or go to Debug and click Start Debugging. Console is opened.. (if it is not then comment below the error).


Now you should have noticed that the title is printed on the left hand side of the command prompt. Now, we will bring this title in center or right hand side (depends on your choice). For this Purpose we will use "\n" and "\t".

"\n" is used to take the cursor to the next line. "\t" is used to provide a tab between text. Both things are used inside the printf() statement under "" (double quotes). For Example - 

printf("\n Maths, Array, Matrix and String Manipulation");

Now the title will be printed in next line instead of the same line. Look at the picture below for more clarification.

No comments:

Post a Comment