Let us dive into C Part-4 (Get some inputs from users)

Spread to the Techies
Hello Everybody…..

I wish you are doing well with C and please give us feedback if you are facing any problem to understand or in the codes.

In my previous post we have learned that how to declare variables for different data types in C and now we are going to use them finally. Please look back if you have missed the previous post.

Now we will use the variable to get inputs from users. We know that a variable assigns some memories when we declare them. We will have to use the memory address to store the value which we will get from the users.

Now, How will you access the Memory Address of a variable????

Dear friends, it’s very simple and easy. We will use an ampersand ‘&’ as prefix of the variable and then the variable itself will be the memory address of the variable. Like:

//VARIABLE DECLARATION:
int a;

//MEMORY ADDRESS WILL BE:
&a; 

Okay now. We are ready to use the variable to get input from users. We will ask users to give two integer values then we will sum them and show the result of their summation.

#include<stdio.h>

int main(){
          int Number1, Number2, Result;

          printf("Enter the First Number: ");
          scanf("%d",&Number1);

          printf("Enter the Second Number: ");
          scanf("%d", &Number2);

          Result = Number1 + Number2;

          printf("The summation of First Number and Second Numbers is: %d", Result);
}

Copy the code and save it as ‘addition.c’ and then build and run (Press, F9).

Now the console will be asking the value for first Number  and press Enter. We have successfully finished a simple interactive two Numbers. Now try yourself: Try to Subtract, Multiply and Divide two numbers where the values will be given by the users.  

N.B: Here  ( * ) is the Multiplying Operator, ( / ) is the Divider and ( – ) is the Subtracting Operator.

 

2 thoughts on “Let us dive into C Part-4 (Get some inputs from users)”

  1. I have read a few good stuff here. Definitely value
    bookmarking for revisiting. I surprise how much attempt you place to make
    any such great informative site.

Leave a Reply

Your email address will not be published. Required fields are marked *