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 Video







arduino abs news








arduino abs Social






A modular, Arduino Mega-controlled delta robot for your desktop.
safe image.php?d=AQDI5lGBL JxubWR&w=720&h=720& content%2Fuploads%2F2019%2F08%2F9154041566833130733 - arduino abs

This interactive floor recalls the precariousness of standing on an icy surface, enhanced with imagery, sounds and physical dynamics.
safe image.php?d=AQDDp  jywcEiEdX&w=720&h=720& v6%252Fshare%252Fplay icon overlay - arduino abs
images  1  normal - arduino abs
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://…

g331p4R  normal - arduino abs
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

metatrona photo

Electrical Box Project Enclosure Case Electronic Wire Dustproof Waterproof DIY

metatrona photo









(Visited 88 times, 1 visits today)

About The Author

You might be interested in

Comment (50)

  1. 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. +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. 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

  2. Or u could just use

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

    printf(“%d \n , age1);
    printf(“%d \n, age2);

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

  3. #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. 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.

  4. 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?

  5. #include

    int main()
    int age= -333;

    printf(” %d”, &age);

    printf(” %d”, age);

    return 0;

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

    1. 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

  6. 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?


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