C calculator (Command based) Part-1

1

Hi everybody,

I think you have clicked the “Programming C” tag because you are interested in C programming language. Okay then you are may be in the right place in the right time. I am also a C programmer and learner but I think I know little bit more than you. If it is then it is a good news for you.  So, why are we waiting for? This C calculator tutorial season will be published part by part. I have divided the project in several parts. I wish all of you have a simple idea on C compiler. I will suggest you to use TC 3.0 compiler. Because this compiler has everything as graphics.h, dos.h, bla bla bla.

Download link:  http://www.4shared.com/zip/Px-HplyX/Turbo_C_30.html

Now we are starting our journey for C.

In a C program we generally have two main parts

  1. Pre  processor  directives
  2. main() function body of the program.Now we are going to write a program to get two integer numbers from user and then to add them and to show the result on the compilers output screen.

#include<stdio.h>
#include<conio.h>

int main(){

int a,b,c;
clrscr();
printf(“Enter two integer numbers\n”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“the result is: %d “,c);
getch();

}

Write this program and save it as .c format and compile then run. Now come to the point of this program. Here we have used two pre processor directives ( #include<stdio.h>, #include<conio.h> ) three variables (a,b,c) five functions (main(), scanf(), printf(), clrscr(), getch() ).

Now what is stdio.h and conio.h why we used them here?

Ans: They are header files. Yeah, we used stdio.h here to use the scanf() printf() functions. The meaning of stdio means Standard I/O and .h is stand for header file. conio.h means Console I/O. We used it here to call clrscr() and getch() function.

What is main(), printf(), clrscr(), scanf(), getch()?

Ans:  these all are built in functions. We will know them gradually turn by turn. main() is used as whole function body, printf() is used here to show output or any message you’ve written to interact with user, clrscr() to clear your console screen, scanf() for getting input from the user, getch() has another use but we use it here to stable the output console until user pressed any key.

Thank you for your patience that you have read it fully. Now place your comment here. We are human being and mistake is one of the characteristics of us. So, please forgive me for any kind of inconvenience here in writing. I have tried my best to give you the best. Your inspiration will boost me up to write more dynamically in future. Till then remain safe and Happy. Goodbye. 🙂

Share.

About Author

Rajumeazi

I am a free learner like to fly in the whole cyber world to gather knowledge. And I know I have only a little to share but I will try my best to give you what I have. :) Thank you :)

1 Comment

Leave A Reply

Powered by themekiller.com