Course C Initial 7th – Training with Math


Lesson 7.
Now, as promised in previous lesson, we’ll go to make some algorithms to practice all knowledge that we learned up to here.
First: Make an algorithm that reserves 3 numbers by user and sum them, after show the result.
For this, we first make the structure as showed below.


How we can see, this is the basic structure of a software in C language. Now, we’ll create the variables for it:


Okay, the variables was created. Now we’ll input the values for them with printf’s and scanf’s how you can see below:


Note: always use return 0; in the end function.
Now we’ll create a new variable called Result that will be the sum of Num1, Num2 and Num3 how you can see below. After we’ll print Result.


That’s finished, we have an algorithm that calculates the sum between 3 numbers. Now, practice this algorithm, write and test yourself, test it change the math operators and joyful.
You could print only the sum, copy it for your compiler:

#include <stdio.h>
int main() {
int Num1, Num2, Num3;
printf ("Type the First Number: ");
scanf ("%d",&Num1);
printf ("Type the Secound Number: ");
scanf ("%d",&Num2);
printf ("Type the Third Number: ");
scanf ("%d",&Num3);
printf ("The Result is: %i",Num1+Num2+Num3);
return 0;
}

What happened? Think.

There’s other way to make this algorithm, that’s just using the printf once. See the image below:


Note: Always type Enter or Spacer-bar if you make an algorithm how you can see above.
The task is finished. That’s all folks and in the next lesson, we’ll see the Oder of Operations in Math.
See you later!

Comentários

More Famous Posts

Course C Initial – 3rd Variables Part. 1

Course Python For Life 3 – Input Command