Multiplication of 2 Numbers: C

In this video tutorial you can learn the procedure followed in C programming to multiply two numbers.

Related Read:

 
#include < stdio.h >

int main()
{
    int a, b, c;

    printf("Enter 2 numbers for multiplication\n");
    scanf("%d %d", &a, &b);

    c = a * b;

    printf("Multiplication of %d and %d is %d\n", a, b, c);

    return 0;
}

Output:
Enter 2 numbers for multiplication
25
5
Multiplication of 25 and 5 is 125

You can write same program without using third variable to calculate multiplication of 2 numbers, as below:

 
#include < stdio.h >

int main()
{
    int a, b;

    printf("Enter 2 numbers for multiplication\n");
    scanf("%d %d", &a, &b);

    printf("Multiplication of %d and %d is %d\n", a, b, (a*b));

    return 0;
}

Output:
Enter 2 numbers for multiplication
25
5
Multiplication of 25 and 5 is 125

Note: Instead of int you can take float variables too. That would help in taking both integer as well as real values from the user as input.

Scanf(): For user input

In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program

Multiplication of Two Numbers: C Programming


[youtube https://www.youtube.com/watch?v=AFbtnOAH7eE]

YouTube Link: https://www.youtube.com/watch?v=AFbtnOAH7eE [Watch the Video In Full Screen.]


This video was produced as building block for our simple calculator application.

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Subtraction of 2 Numbers: C

In this video tutorial you can learn the procedure followed in C programming to subtract two numbers.

Related Read:

 
#include < stdio.h >

int main()
{
    int a, b, c;

    printf("Enter value of a and b\n");
    scanf("%d%d", &a, &b);

    c = a - b;
    
    printf("Subtraction of %d and %d is %d\n", a, b, c);

    return 0;
}

Output:
Enter value of a and b
30
20
Subtraction of 30 and 20 is 10

You can write same program without using third variable to calculate subtraction of 2 numbers, as below:

 
#include < stdio.h >

int main()
{
    int a, b;

    printf("Enter value of a and b\n");
    scanf("%d%d", &a, &b);

    printf("Subtraction of %d and %d is %d\n", a, b, (a+b));

    return 0;
}

Output:
Enter value of a and b
30
20
Subtraction of 30 and 20 is 10

Note: Instead of int you can take float variables too. That would help in taking both integer as well as real values from the user as input.

Scanf(): For user input

In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program

Subtraction of Two Numbers: C Programming


[youtube https://www.youtube.com/watch?v=2cAMGtToJNE]

YouTube Link: https://www.youtube.com/watch?v=2cAMGtToJNE [Watch the Video In Full Screen.]


This video was produced as building block for our simple calculator application.

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Addition of 2 Numbers: C

In this video tutorial you can learn the procedure followed in C programming to add two numbers.

Related Read:

 
#include < stdio.h >

int main()
{
    int a, b, c;

    printf("Enter value of a and b\n");
    scanf("%d%d", &a, &b);

    c = a + b;
    
    printf("Addition of %d and %d is %d\n", a, b, c);

    return 0;
}

Output:
Enter value of a and b
30
20
Addition of 30 and 20 is 50

You can write same program without using third variable to calculate addition of 2 numbers, as below:

 
#include < stdio.h >

int main()
{
    int a, b;

    printf("Enter value of a and b\n");
    scanf("%d%d", &a, &b);

    printf("Addition of %d and %d is %d\n", a, b, (a+b));

    return 0;
}

Output:
Enter value of a and b
30
20
Addition of 30 and 20 is 50

Note: Instead of int you can take float variables too. That would help in taking both integer as well as real values from the user as input.

Scanf(): For user input

In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program

Addition of Two Numbers: C Programming


[youtube https://www.youtube.com/watch?v=YYRSBD7HJTQ]

YouTube Link: https://www.youtube.com/watch?v=YYRSBD7HJTQ [Watch the Video In Full Screen.]


This video was produced as building block for our simple calculator application.

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

range Input Type: HTML5

Browsers which support range input type know that the field is used for entering a number with in a given range.

form-input-type-range-type-html5

User Interface(UI) enhancement wise, you may get a slider control to select a range of number. You can even use min, max and step attributes to provide additional control for the field – for setting the range.

HTML file
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
< !DOCTYPE html>
<html>
<head>
<title>range Input Type: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
<script src="myScript.js"></script>
</head>
<body>
 
<form>
<label>Range(2 to 10): </label>
 <input type="range" min="2" max="10" id="get" step="0.2" onchange="fetch()"/>
 <input type="number" min="2" max="10" step="0.2" id="put" />
 <input type="submit"/>
</form>
 
</body>
</html>

Here we have 2 input fields of type range and number respectively. Both having minimum allowed value as 2 and maximum allowed value as 10, and a step of 0.2 (fractional value). The number input field is taken for the sake of illustrating the value selected by the user using the range input field – by using(sliding) the slider.

JavaScript file
myScript.js

1
2
3
4
5
function fetch()
{
var get  = document.getElementById("get").value;
document.getElementById("put").value = get;
}

Here we fetch the value selected by the user using the slider and assign the value to the number input field.

CSS file associated with this is same as present at pattern and title Attribute of Form Field: HTML5

Form Input Type – range: HTML5


[youtube https://www.youtube.com/watch?v=YecwKiFBt0s]

YouTube Link: https://www.youtube.com/watch?v=YecwKiFBt0s [Watch the Video In Full Screen.]



Note: Browsers which do not support range input type, simply fall back to text input type. However, you need to validate the user entered data at server-side for more security. Client side validation is done mainly for the sake of creating the illustration of speed of validating the data and for a better user experience.

Find Sum of Digits In A Given Number: C

Video Tutorial to illustrate, C Program to find sum of digits in the given/user entered integer number.

In this program we assign variable sum = 0 to avoid garbage values in sum before the calculation, which would result in wrong output.
We store the user entered value in num.

1
2
3
4
5
6
 while( num )
  {
    rem = num % 10;
    sum = sum + rem;
    num = num / 10;
  }

Here the loop executes until the value of num is zero.

If user enters 123, we apply the modulus to get the individual values.
Ex:
123 % 10 = 3
12 % 10 = 2
1 % 10 = 1

We get 123, 12 and 1 by dividing the original value by 10.
Ex:
123 user entered value.
123 / 10 = 12
12 / 10 = 1

Now the sum.

sum = sum + rem;

3 = 0 + 3
5 = 3 + 2
6 = 5 + 1

So the sum of digits in the given integer number is 6.

Video Tutorial: Find Sum of Digits In A Given Number: C


[youtube https://www.youtube.com/watch?v=UnXfCTtHNWw]

YouTube Link: https://www.youtube.com/watch?v=UnXfCTtHNWw [Watch the Video In Full Screen.]



Full Free Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include < stdio.h >
#include < conio.h >
 
void main()
{
int num, rem, sum = 0;
clrscr();
 
printf("Enter an integer number\n");
scanf("%d", &num);
 
while(num)
{
  rem = num % 10;
  sum = sum + rem;
  num = num / 10;
}
 
printf("\nThe sum of digits is %d", sum);
getch();
}

Output:
Enter an integer number
123
The sum of digits is 6