In this tutorial we shall start learning Programming through C.As a basic program of every programming language we shall start with Hello world program and some basic arithmetic program.
For a Hello world we need to just display the “Hello world” to user.For this we shall use printf statement which we explained in our earlier post.As we are using an output statement we include stdio.h header statement.
The program of Hello World is:
#include<stdio.h> void main() { printf("HELLO WORLD"); }
OUTPUT:
HELLO WORLD
This is how we need to use the input/output statement in body of a program.Now we shall write a program to perform all the basic arithmetic operation on inputs given by user using scanf() statement.The flow of the program is:
1.We need to get two values from the user.
2.Perform all basic arithmetic operation such as: addition,subtraction,multiplication,division.
3.Display those output values to the user with respective text display.
The main important point in usage of division is we get the remainder as an output of division performed.
Now we shall write the code basing on above guidelines:
#include<stdio.h> void main() { int x,y; //Declaration of integer type variables int add,sub,mul,div; printf("\n Enter first integer value as an input:"); scanf("%d",&x); //Getting the value from user and storing it in x. pirntf("\n Enter second integer value as an input:"); scanf("%d",&y); //Getting the value from user and storing it in y. add = x+y; sub = x-y; mul = x*y; div = x/y; printf("\n Addition of given two numbers is:%d",add); printf("\n Subtraction of given two numbers is:%d",sub); printf("\n Multiplication of given two numbers is:%d",mul); printf("\n Division of given two numbers is:%d",div); }
OUTPUT:
You can download the arithmetic program:download
I’m pretty pleased to discover this page. I need to to thank you for
your time just for this fantastic read!! I definitely loved every little bit
of it and I have you bookmarked to see new stuff on your web site.