QUICK MAKE A PROGRAM THAT AVERAGES 3 INTEGERS

QUICK MAKE A PROGRAM THAT AVERAGES 3 INTEGERS

Other urls found in this thread:

gist.github.com/lolzballs/2152bc0f31ee0286b722
twitter.com/SFWRedditGifs

cuck

Some Indian on Fiverr

she has an ugly face but nice boobs

avg(x, y, z)

I like her because of her face

[a, b, c].reduce((a, b)=>{return a+b})/3;

her face is appealing in some weird way. she has a look like she's holding back a smirk. a lot of people find that really attractive.

in before "well those people are WRONG"

numbers = [int(input('number?')) for _ in xrange(3)]
print sum(numbers) / 3.0


what's next boss?

MEAN MEDIAN OR MODE

AVERAGE ALWAYS IMPLIES MEAN.

allowing user input like this (or rather, leaving it to this part of the code) means taking on more risk.

just define a function that takes 3 integers and returns the average. don't implement code to prompt a user. if anything, that's just obnoxious. imagine if every time a developer committed code to a large codebase someone had to go and strip out all the gimmicky terminal CLI prompts so other code could just pipe in values the way complex systems are supposed to work?

int x,y,z, sum;
double avg;
cout > x;
cin >> y;
cin >> z;

sum = x+y+z;
avg = (sum/3);

cout

is there any context where "average" translates to median or mode?

i could maybe buy the median argument, kind of. like it would be a little presumptuous to ask if i meant median if i asked you to average something, but i see where your head is at. mode, however, is a stupid misunderstanding. you'd have to be a retard to need that clarification.

whoops, meant
avg = (3/sum);

desu, OP was vague with his post, and my brain just thought of this right away, so fuck it lol

okay can someone explain why you people are implementing command line prompts? do you think it's some sort of flourish that makes your code more impressive or something? are you just not getting how requirements engineering works?

i feel like if you people were tasked to build a bridge we'd come back and see you repaving the whole fucking city.

function avg(a,b,c){
return a+b+c/3
}

what aspect of it was vague? it couldn't have been the word "averages". so why did you ask about that part?

idk, i'm anxious

This was just how I was taught in my school, we were taught to be friendly for the end user lol. Next time I will be barebones with my function

you got anxious from someone posting all caps? do you honestly have a disability or something?

Maybe lol, if anything, it has not been diagnosed.

If you were measuring a signal that was like a dc signal with noise. It would be useful to use mode if your only concerned with the dc component.

median would be useful if the goal was ultimately pick the middle item. Like if your trying to talk with a student that is middle of the pact.

Thanks, I learned how to code it from that snippet.

Done. Why are her tits so small?

do try. in the real world people don't want you to code a function and then wrap it up with a nice bow on top; they just want it to take sane inputs and give back the right outputs. that means documenting functions but not being obnoxious with interactive prompts and stuff.

and besides that, thinking about the code in the sense of writing the logical aspects (the part that just averages 3 integers, or does whatever else) as separate from the part that interacts with the human being is good practice. we could have a much longer thread about the best ways to get user input given the nearly infinite ways users can disappoint you.

reminds me of a perpetual :3 smiley

Dude get fucked. Honestly who gives a shit if he add some command line text.

It's not like you know the context of the fucking question. Op provided no context.

I bet you think you're the smartest guy in the room.

You didn't specify how it would be taking inputs you shitter.

Thanks for the constructive criticism, I appreciate it, friend. :) Not being sarcastic; anything that will refine and develop my skills is paramount for my success. One day when I am successful, I will remember everything people has told me, good or bad, so thank you again, friend.

>le my code is better meme

Which GPU is best?

You need to keep in mind he mentioned requirements engineering which you were given shitty requirements criteria, so don't let him make you feel guilty. He's projecting without clarifying.

calculating the sum will cause the function to break if the total exceeds the integer max. Similar fuckups if casting the number to a float, although python by default uses double floating point numbers.


You could do something like

int average(int a, int b, int c ){
int tmp = (a+b) >> 2;
return (tmp+c);
}

intel hd3000

I'm lonely

.... sure, but i'm not asking when it would be better to take a median or a mode. i'm asking in what context or field the word "average" refers to the median or mode.

if someone with a high school education asks for an average, you should assume that they know what they're asking for. just like if they asked you to bring a chair, you shouldn't ask if they meant an ottoman or a table.

function average(){
var add = 0;

for(i in arguments){
add += arguments[i];
}

return add / arguments.length;
}

the hd 4850 was ahead of its time

the 275 too

>calculating the sum will cause the function to break if the total exceeds the integer max
not in python you melt

but it takes inputs, right? are there any user input formats that only take strings? `cin` takes in streams of text. same with python's `input`.

if the prompt is to write something that takes 3 integers and returns the average, you have two good options:

1) either trust that the input they say you'll get is what you will always get, or
2) ask.

what you've all done is option #3, which is implement on the assumption that something else will actually happen, which is a user stepping up to a keyboard and typing in numbers. why not implement a parser to take text like "three" and turn it into 3?

What you don't assume all 4channers have Ph'd in mathematics?

i don't think at any point in your phd program you learn to think of "average" as meaning something other than... you know... the average. you would just develop an even deeper appreciation for the more apt uses of median and mode

>not even bothering to read the rest of the sentence.

I see it and I like it too, her face is still ugly tho

a = input("int 1 ")+input("int 2 ")+input("int 3 ")/3
print(a)

print(int(input("int 1 "))+int(input("int 2 "))+int(input("int 3 "))/3)

#include
int x,y,z,sum;
double val;
int main(int x, int y, int z){
sum = x + y + z;
val = sum/3;
printf("%d",val);
return 0;
}

eh, you asked for a situation where you'd assume that average means median or mode. Obviously, you'd assume that it means mean but there are a couple of context where that would not be the case.

Honestly, what were running up against here is the fact that english is a terrible way to describe what happens in math.

(lambda (x y z) (/ (+ x y z) 3))

#include
#include
int main(int argc, const char * argv[])
{
int numbers[] = {10,20,30};
std::cout

or

(define (avg . args) (/ (apply + args) (length args)))

if(p==0)
return avg=(x*y*z).^(1/3)
end
if(isinf(p))
return max(x,y,z)
end
if(isinf(-p))
return min(x,y,z)
end
return avg=((x.^p + y.^p + z.^p)/3).^(1/p)

(a,b,c) => {a+b+c/3}

import time

a = input('First integer:')
b = input('Second integer:')
c = input('Third integer:')

avr = (float(a) + float(b) + float(c)) / 3
print (avr)
time.sleep (10)

#If you want to test it, copy all this into a text document, and rename it something.py, then run it (in command prompt if you don't have the stock python app)

var avg = function (a,b,c){
return (a+b+c)/3;
}

Why bother summing before taking the average? You can just say avg = (x+y+z)/3.

NEWFAG DETECTED.

int64_t average(int32_t numbers[], int16_t numbers_length)
{
int64_t final;
for(int a = 0; a < numbers_length; a++)
{
final = final + (numbers[a]/numbers_length);
}
return final;
}

Oh fuck me, since when is final a reserved word?

MS paint.

Who is this hawk-looking semen demon?

the code plugin has no idea what language you're posting in, so it colors anything that's a reserved word in any language.

geometric, harmonic, or arithmetic?

Margaery Tyrell (Natalie Dormer)

> (OP)
>she has an ugly face but nice boobs
I actually quite like her

nums = [1,2,3]
main = print (sum nums / 3)

using namespace std;
int main()
{
int int1;
int int2;
int int3;
cin >> int1;
cin >> int2;
cin >> int3;
int low;
int high;

if (int1 = int3)
high = int2;
else
high = int3;

int average;
average = low;
while (average int1 + int2 + int3)
break;
average++;
}
cout

=SUM(A2;B2;C2)/3

int tmp = (a + b) >> 2
So desugared: int tmp = (a + b) / 4
(tmp + c) >> 2 -> (tmp + c) / 4

So the return value is:
a/16 + b/16 + c/4 which is tottaly equal to a/3 + b/3 + c/3

Public Sub averageFunction()

Dim x, y, z As Integer = Nothing
Dim Average As Double = Nothing

Average = (x+y+z+)/3;
Console.WriteLine(Average)

Matlab:

mean([1,2,3])

boring desu senpai

Java 8:
public static void main(String args[]) {
double avg = Stream.of(args).mapToInt(Integer::parseInt).average().getAsDouble();
System.out.println(avg);
}

x=(a+b+c)/3

PWHEH

Her boobs are saggy

fn average_of_3_ints(x: i32, y: i32, z:i32) -> f64 {
(x + y + z) / 3
}

avg = (a, b, c) => (a+b+c)/3

>a + b + (c/3)
you tried to use less keystrokes and broke your code instead, nice job

Well first since its obvious the only reason you're giving me such a hard question is because you're afraid of hiring a strong african american woman. And no I will not even start to answer I'm reporting you to the NAACP

>implying that's bad

lol dummy

>python by default uses double floating point numbers
confirmed for not knowing shit about Python.
Maybe you're thinking of JS?

double avg(int a, int b, int c) {
double x = a/3 + b/3 + c/3;
x+= ((double) a%3 + b%3 + c%3) / 3;
return x;
}

In C, so the line with the modulo operator might be incorrect depending on the implementation being used

average [a, b, c]

avg = (0+0+0)/3
print(avg)

it doesn't say which three integers, so I chose 0, 0 and 0

How is that better than just:
((double) a + (double) b + (double) c) / 3 ?

Is it faster?

Kek

I made another version:
#include
int main(int argc, const char * argv[])
{
int numbers[] = {10, 20, 30};
int m = 0, i = 0;
while(i < 3) m += (numbers[i++] - m) / (i + 1);
std::cout

Is this the new shitposting?

Posing stupidly easy programming challenges?

he wanted to avoid overflow problems

Quick make a program that prints "Goodbye World!".

I could only do hello world :*)

gist.github.com/lolzballs/2152bc0f31ee0286b722

def func(list_of_numbers):
return sum(list_of_numbers)/1.0/len(list_of_numbers)

for(var i=0; i

Do your own homework faggot

public double avg(int a,b,c){
return (a+b+c)/3;
}

>ugly face

u wot m8
Her face is aesthetic as fuck

#include
#include
#include
using namespace std;
int main() {
double sum = 0;
string input[3];
for (int x =0; x < 3; x++) {
cout

def average(arrayOfInts):
return sum(arrayOfInts)/len(arrayOfInts)

> [a, b, c].reduce((a, b)=>{return parseInt(a)+parseInt(b)})/3;

ftfy

(defun average-integers (&rest ints)
(/ (apply #'+ ints)
(length ints)))

(average-integers 4 3 2) ;; => 3
(average-integers 389 3289 2789127 282828111) ;; => 2828281111

I am gay, and even I can confidently say you are talking bullshit. She looks amazing.