# arduino abs

Because you’re going to allow the user to answer to values such as May they’re calculating their age. Well, what if they put the year that they were born first like 1986, and they said, try to subtract the current year from it like 2014? Well, if they did that, then it’s going to give you a negative number, because you’re subtracting a bigger number from a smaller one and of course their age wouldn’t be negative 28. So you need to convert that to a positive number. So your program doesn’t crash so again, it’s good for distances and weights and ages. So I’ll show you guys how to build a simple program like that right now, so we’ll go ahead and put into year 1 and int year 2, which is pretty much going to be the two years that they enter to calculate the age of something and we’re Store the final age right there now for printf let’s just go ahead and give them a nice little prompt on the screen be like enter a year now enter a tear. You have to be crying to use this program. All right enter a year, newline and we’ll. Just scanf and for this, of course, for scanning percent D, since we love weird with integers and ampersand year and tyr year, one all right so now, whatever value they entered, hopefully it was an integer. We store it in year, one of course we need to do this again enter another year and store that in year.

Two, so now we got two numbers integers. So the first thing we need to do is make an equation to calculate the age. So H equals year 1 minus year 2. Now this actually doesn’t matter since we’re going to be using absolute value, you can put your two minus two one. You know it won’t make a difference, cool little thing about this. So what I want to do after this is actually print out the value that we came up with first, the value or the original value that we calculated without using absolute value so for now percent the new line and age. Now, after this, what we’re going to do is we’re, going to figure that this number that we came up with can either be the correct one if they entered armed, you know one of the numbers first or the wrong one. It can be negative if they enter the smaller number first, so no matter what we want to go ahead and calculate the absolute value using the function, a be s. So, whenever we pass age into here, if it’s a negative number is going to convert it, convert it into the positive number. If it’s positive is just going to leave it the same so now when you print that bad boy out again check it out, enter your year, 1986 enter another year, 2014, okay, so this one they tried to subtract 2014 from 1986 and it got negative 28.

Well, you don’t want to put that into your program, or else it’s going to crash everything later on. So the absolute value converts that to 28 and of course, if they entered it correctly, which is 2014 1986, it calculates 28 and leaves it at 28. So again, whenever you’re developing software, you always want to assume that the user is going to F something up and you want to make your program is user proof as possible. So using absolute value is a great way to do that sometimes it’s necessary whenever you’re using distances like. If I was to put two distances in there, then either way would be the correct way for the user. So you would still need to use absolute value, same thing with weights and so on and so forth, so um for now, that’s – probably good for this tutorial. Thank you guys for watching actually might as well show you guys some other small ones. Real quick and uh let’s see what I can do go ahead and do this so we’ll just use one print statement and we’ll print out a couple floats and I don’t need to make a whole tutorial for these um. The first one is this function POW. Now this means is, whenever you run this, you have to punch your computer as hard as you can until your fist goes. Pow I’m just kidding actually stands for power, and you need to enter two values for this.

The first one is the base and the second one is the exponent. What this is pretty much saying is: I want to see 5 to the third power. So if you guys don’t know what this is, it should be 125, so pretty much 5 times. 5 is 25 times, 5 is 125, so that’s. What that does again, I don’t need a whole tutorial explaining that and the only other one I wanted mention. Real quick is SQ RT. This stands for squirt and you have to squirt water on your computer. Just kind of good, so this actually stands for square root and whatever number you pass in like 164, it prints the square root of that number. So before I run this, can you guess what it is square root of 164? Probably, on a twelve point, six or something twelve point – eight I was close, but basically the square root of 164 is twelve point. Eight, maybe you guys gets closer than me. So those are a few math functions again out of all of those you’re, probably going to be using absolute value the most, but now you have the power function and square root on hand so well for now.

# arduino abs Social

official.arduino
2019-09-12T13:55:21+0000

A modular, Arduino Mega-controlled delta robot for your desktop.
official.arduino
2019-09-12T12:41:57+0000

This interactive floor recalls the precariousness of standing on an icy surface, enhanced with imagery, sounds and physical dynamics.

BalamSinhue
Tue Feb 28 05:37:05 +0000 2012

RT @arduino: Researchers are designing a convolutional neural network approach towards self-driving cars with the help of Arduino: https://…

pablobgp
Wed Jul 22 19:22:37 +0000 2009

RT @arduino: Researchers are designing a convolutional neural network approach towards self-driving cars with the help of Arduino: https://…

Portable USB Vacuum Electric Pump Quick Seal Bag Strong Suction for Food Storage

Electrical Box Project Enclosure Case Electronic Wire Dustproof Waterproof DIY

2016-04-15T14:35:45

2016-04-15T14:35:40

2016-04-15T14:35:36

(Visited 88 times, 1 visits today)

## Comment (50)

1. Merser says:

when i learn how old i am, i cant help but leave a tear

1. Unknown Account says:

How old are you

2. Merser says:

gurl thas none of yo bidness

3. Unknown Account says:

4. Merser says:

@Unknown Account PLease shut UP 🙂

5. Chainsaw Subjugate says:

You are 98, I make pretty good assumptions.

2. Isabelle Ortiz says:

Hi Bucky, since you mentioned that puts and gets are better, why do you still use printf and scanf instead of gets and puts?

1. Mihkel Tedremaa says:

+Isabelle Ortiz Hi. I’m just learning C programming, but according to my understanding, puts and gets are meant for printing/scanning chars or strings only… in this tutorial, we use integers (numbers). In printf/scanf, we define the variable type after “%” and therefore we can use different ones, than just chars or strings…

2. Abdulnaser Sheikh says:

You can just do this
int year1,year2,age;
int year1;
int year2;
int age;

3. Kouhakushiro says:

Gets and puts are very unsafe functions because they lead to buffer overflow and are not used anymore.You can use other function in their place like fgets gets_s etc

4. Gordon Matthew says:

scanf is unsafe aswell

5. TheUltraGamer says:

@Gordon Matthew It’s Safe compared to Gets

3. Aetricity says:

I actually guessed 12.8 (not the full thing) for the square root, so that’s great.

4. Kevin Verdhi says:

Or u could just use

int age1 = year1 – year2
int age2 = year2 – year1

if(year1>year2){
printf(“%d \n , age1);
}else{
printf(“%d \n, age2);

1. Peterolen says:

You could, but don’t you think _abs_ has certain advantages?
int age = abs(year1 – year2);
printf(“%d”, age);

2. Brutal Butler says:

Very untrue, the person reviewing your code will look down on you for it

3. Leandro170 says:

oh hey,an alive person

*wanna pley my gaem?*

4. Burak Unutmaz says:

No.. wtf.. 2 years later but still, no.

5. ganesh vicky says:

#include
#include
#include

int main()
{
printf(“%f\n”, pow(64,1/3));
return 0;
}

The result of the above program is always 1. But here im trying to find the cubic root of 64
can anyone help me out?

1. Заклетник says:

I don’t think that you can put a number to the power of 1/3

2. Kai Chu says:

make sure u have decimals and make it consistent e.g. pow(64.0,(1.0/3.0)). if the result is going to have decimals u need to have at least 1 d.p. e.g. 1/3 would give 0.333 so u should type 1.0/3.0 or with more decimals instead of 1/3. since datatype was set as float, the computer refused to compute with integers. Also it’s a good practice to predefine the datatype as if not done the computer will guess it for you (probably why ur code didn’t work) e.g. float a=64; float b=1; float c=3; in this way you don’t need to type the decimals.

3. Gollum Ei says:

lmao

6. yerrapotu kiran says:

Danke danke Bucky

1. Abdulnaser Sheikh says:

You can just do this
int year1,year2,age;
int year1;
int year2;
int age;

7. Abdulnaser Sheikh says:

You can just do this
int year1,year2,age;
int year1;
int year2;
int age;

1. Stamvid says:

It looks better 😀

8. koren gershoni says:

int diceRoll1, diceRoll2, diceRoll3;
int firstSum, SecondSum;
char guess;

diceRoll1 = ( rand()%6 ) + 1;
diceRoll2 = ( rand()%6 ) + 1;
diceRoll3 = ( rand()%6 ) + 1;

firstSum = diceRoll1 + diceRoll2 + diceRoll3;
printf(“First sum of dices: %d \n”, firstSum);

puts(“do you think the next sum will be lower/same/higher? (L,S,H)”);
scanf(” %c”, &guess);

diceRoll1 = ( rand()%6 ) + 1;
diceRoll2 = ( rand()%6 ) + 1;
diceRoll3 = ( rand()%6 ) + 1;

SecondSum = diceRoll1 + diceRoll2 + diceRoll3;
printf(“second sum of dices: %d \n”, SecondSum);

if(guess == ‘L’ && firstSum > SecondSum) puts(“Your rock!”);
else if(guess == ‘S’ && firstSum == SecondSum) puts(“Your Rock!”);
else if(guess == ‘H’ && firstSum < SecondSum) puts("Your rock!"); else printf("Your Sucks!"); return 0; how is that?

9. ZoRo says:

the command abs is in which library?

1. Cuan Clifford says:

#include

2. Peterolen says:

The abs function is actually declared in the header.

3. Ashutosh Pandey says:

math.h

10. a j says:

#include
#include
#include
#include
#include

int main()
{
int age= -333;

printf(” %d”, &age);

age=abs(age);
printf(” %d”, age);

return 0;
}

can you tell me why I have 2686748 333 ?
%d should match with & age right?

1. Peterolen says:

You used printf instead of scanf.

2. Peterolen says:

Unsigned types can’t store negative values.

11. G G says:

this doesnt work on linux, any way to make it?

1. Peterolen says:

What is it that doesn’t work? Do you get an error message?

12. Stamvid says:

Oh wow 0 dislikes on a 50k video, i have never seen that before :O

1. Diktator70 says:

well, thanks to you m8, now the vid has one dislike. nice job, a**hole

2. Gobberfisch says:

266:1 is still a very nice rating

3. Diktator70 says:

yeah, thats like, 532:2

4. Stamvid says:

Update: It’s now at 3

Is abs function some thing like this? :
int abs(int number)
{
return number * (-1);
}

1. Anshu Thakur says:

Shadow Meth No, because by this logic it will convert a positive number into a negative after absolute function…….eg: if number = 4 , then return would be 4*(-1) i.e. abs(4) = -4 which is completely wrong,,I guess

14. Star_ Media says:

awesome

15. Sabre Mase says:

So when I enter this the way you have it shown here. I get errors saying “variable year1, (and year2 and age) are not initialized. I can easily fix it by making year1, year2 & age = 0 but why do i have to do that?

16. AJay Gupta says:

use *fabs( )* to find absolite value of float data type.

17. Osama Gamal says:

sqrt and fabs
if you know what I mean.

18. Alex Shepler says:

he said something weird at 1:29

19. Lluís Mª Bosch says: