[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
QUICK MAKE A PROGRAM THAT AVERAGES 3 INTEGERS
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 18
File: 1467330151091.jpg (82 KB, 600x900) Image search: [Google]
1467330151091.jpg
82 KB, 600x900
QUICK MAKE A PROGRAM THAT AVERAGES 3 INTEGERS
>>
Some Indian on Fiverr
>>
>>55484925
she has an ugly face but nice boobs
>>
avg(x, y, z)
>>
>>55484951
I like her because of her face
>>
[a, b, c].reduce((a, b)=>{return a+b})/3;
>>
>>55484951
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"
>>
>>55484925
numbers = [int(input('number?')) for _ in xrange(3)]
print sum(numbers) / 3.0


what's next boss?
>>
>>55484925
MEAN MEDIAN OR MODE
>>
>>55485204
AVERAGE ALWAYS IMPLIES MEAN.
>>
>>55485194
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 << "Enter three whole numbers. ";
cin >> x;
cin >> y;
cin >> z;

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

cout << "This is the average of your three intergers: " << avg;

return 0;

>>
>>55485204
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.
>>
>>55485230
whoops, meant
avg = (3/sum); 
>>
>>55485241
desu, OP was vague with his post, and my brain just thought of this right away, so fuck it lol
>>
>>55485230
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.
>>
>>55484925
function avg(a,b,c){
return a+b+c/3
}
>>
>>55485258
what aspect of it was vague? it couldn't have been the word "averages". so why did you ask about that part?
>>
>>55485272
idk, i'm anxious
>>
>>55485261
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
>>
>>55485299
you got anxious from someone posting all caps? do you honestly have a disability or something?
>>
>>55485310
Maybe lol, if anything, it has not been diagnosed.
>>
>>55485241
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.
>>
>>55485230
Thanks, I learned how to code it from that snippet.

>>55484925
Done. Why are her tits so small?
>>
>>55485307
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.
>>
>>55485177
reminds me of a perpetual :3 smiley
>>
>>55485367
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.
>>
>>55485261
You didn't specify how it would be taking inputs you shitter.
>>
>>55485367
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?
>>
>>55485416
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.
>>
>>55485230
>>55485194
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)>>2;
}
>>
>>55485420
intel hd3000
>>
>>55485437
I'm lonely
>>
>>55485361
.... 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;
}
>>
>>55485420
the hd 4850 was ahead of its time

the 275 too
>>
>>55485440
>calculating the sum will cause the function to break if the total exceeds the integer max
not in python you melt
>>
>>55485401
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?
>>
>>55485454
What you don't assume all 4channers have Ph'd in mathematics?
>>
>>55485489
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
>>
>>55485483
>not even bothering to read the rest of the sentence.
>>
>>55485177
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)
>>
>>55485526
print(int(input("int 1 "))+int(input("int 2 "))+int(input("int 3 "))/3)
>>
#include <stdio.h>
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;
}
>>
>>55485507
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 <iostream>
#include <numeric>
int main(int argc, const char * argv[])
{
int numbers[] = {10,20,30};
std::cout << std::accumulate(numbers,numbers+3,0) / 3;
return 0;
}
>>
>>55485613
or

(define (avg . args) (/ (apply + args) (length args)))
>>
>>55484925
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;
}


>>55485230
Why bother summing before taking the average? You can just say avg = (x+y+z)/3.
>>
>>55485747
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;
}
>>
>>55485806
Oh fuck me, since when is final a reserved word?
>>
>>55484925
MS paint.
>>
>>55484925
Who is this hawk-looking semen demon?
>>
>>55485816
the code plugin has no idea what language you're posting in, so it colors anything that's a reserved word in any language.
>>
>>55485226
geometric, harmonic, or arithmetic?
>>
>>55485858
Margaery Tyrell (Natalie Dormer)
>>
>>55484951
>>>55484925 (OP)
>she has an ugly face but nice boobs
I actually quite like her
>>
>>55484925
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 <= int2 && int1 <= int3)
low = int1;
else if (int2 <= int1 && int2 <= int3)
low = int2;
else
low = int3;

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

int average;
average = low;
while (average <= high) {
if (average + average + average > int1 + int2 + int3)
break;
average++;
}
cout << average - 1;
}
>>
>>55484925

=SUM(A2;B2;C2)/3
>>
>>55485440
 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)
>>
>>55484925

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);
}
>>
>>55484925
x=(a+b+c)/3

PWHEH
>>
>>55484951
Her boobs are saggy
>>
>>55484925
fn average_of_3_ints(x: i32, y: i32, z:i32) -> f64 {
(x + y + z) / 3
}
>>
>>55484925
avg = (a, b, c) => (a+b+c)/3
>>
>>55485266
>a + b + (c/3)
you tried to use less keystrokes and broke your code instead, nice job
>>
>>55484925
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
>>
>>55486357
>implying that's bad
>>
>>55485747
lol dummy
>>
>>55485522
>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
>>
>>55486783
How is that better than just:
((double) a + (double) b + (double) c) / 3 ?

Is it faster?
>>
>>55485869
Kek
>>
>>55485617
I made another version:
#include<iostream>
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 << m;
return 0;
}
>>
File: 1440456546651.jpg (102 KB, 1280x936) Image search: [Google]
1440456546651.jpg
102 KB, 1280x936
>>55484925
Is this the new shitposting?

Posing stupidly easy programming challenges?
>>
>>55486990
he wanted to avoid overflow problems
>>
>>55487320
Quick make a program that prints "Goodbye World!".
>>
>>55487362
I could only do hello world :*)

https://gist.github.com/lolzballs/2152bc0f31ee0286b722
>>
>>55484925
def func(list_of_numbers):
return sum(list_of_numbers)/1.0/len(list_of_numbers)
>>
>>55487362
for(var i=0; i<1; i++){ console.log("goodbye wold"); }
>>
File: 1463721060895.jpg (20 KB, 298x395) Image search: [Google]
1463721060895.jpg
20 KB, 298x395
>>55484925
Do your own homework faggot
>>
public double avg(int a,b,c){
return (a+b+c)/3;
}
>>
File: yes you do.jpg (51 KB, 614x572) Image search: [Google]
yes you do.jpg
51 KB, 614x572
>>55484951
>ugly face

u wot m8
Her face is aesthetic as fuck
>>
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main() {
double sum = 0;
string input[3];
for (int x =0; x < 3; x++) {
cout << "Number " << x+1 <<":";
getline(cin,input[x]);
sum += atoi(input[x].c_str());
}
cout << endl << sum/3.0;
}
>>
def average(arrayOfInts):
return sum(arrayOfInts)/len(arrayOfInts)
>>
>>55485166
> [a, b, c].reduce((a, b)=>{return parseInt(a)+parseInt(b)})/3;

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

(average-integers 4 3 2) ;; => 3
(average-integers 389 3289 2789127 282828111) ;; => 2828281111
>>
>>55484951
I am gay, and even I can confidently say you are talking bullshit. She looks amazing.
>>
>>55488600
stop being so gay
>>
>>55488653
I can't anon, you're just too damn attractive
>>
>>55484925
Is this your homework or some shit?
>>
>>55488600
do you like putting carrots up your bum?
>>
num1 = int(input("Insert 1st number"))
num2 = int(input("Insert your 2nd number"))
num3 = int(input("Insert your 3rd number"))

print((num1+num2+num3)/3)
>>
Trips, whitness them
>>
>>55484925
Will I get b& if I post her tits itt?
>>
>>55488811
BLUE FUCKING BOARD
>>
>>55488811
Mods doing their job
>>
>>55486110
What's in A1, B1 and C1?
>>
>>55488876
Passwords for cp dumps
>>
>>55488811
Hold your horses, she was 16 in that
>>
>>55484925
Undefined behavior in 3/4 cases.

Please detail your program specification.
>>
>>55488882
Neat
>>
>>55485816
>performing n division operations
>n rounding errors
>when you could have one division, one rounding error
w h y
>>
10 print nice tits
20 print butterfacetho
30 goto 10
>>
#include "stdafx.h"


int main()
{
float num1, num2, num3, average;
printf("First number: ");
scanf("%f", &num1);
printf("\nSecond number: ");
scanf("%f", &num2);
printf("\nThrid number: ");
scanf("%f", &num3);
average = (num1 + num2 + num3) / 3;
printf("\n\nYour average is %f.\n", average);

return 0;
}


Just started taking a C class at college. How did I do?
>>
>>55485441
After driving around town for some time I came to the same conclusion. Thanks anon, you opened my eyes.
>>
>>55485441
Actually I changed my mind again
>>
>>55489375
>QUICK MAKE A PROGRAM THAT AVERAGES 3 INTEGERS
>INTEGERS
>>
>>55485230

This is wrong

(sum/3);


This part does integer division and will return an integer (not a decimal). At least one of the operands needs to be a decimal.
>>
>QUICK MAKE A PROGRAM THAT AVERAGES 3 INTEGERS

No. Why should I? What's the incentive? Where's the bird with the knife?
>>
++[------>+<]>---.--[--->+<]>-.[--->++++<]>-.--[--->+<]>-.+[->+++<]>++.--[--->+<]>.[->+++<]>.++++++.++++.
>>
>>55490050
>she
>>
(defun avg (&rest args) (/ (reduce #'+ args) (length args)))

Arbitrary precision rational arithmetic > cshit
>>
>>55484951
she has a nice face but boobs are too small
>>
>>55485572
>global variables
scum
>>
Here you go OP I hope your professor likes it!
>>
>>55484925
#include<stdio.h>
float avrgThree(int a, int b, int c){
return (a + (float) b + c) / 3;
}

int main(){
int a, b, c;
a = 0;
b = a;
c = b;
printf("a = ");
scanf("%i", &a);
printf("b = ");
scanf("%i", &b);
printf("c = ");
scanf("%i", &c);
printf("%f", avrgThree(a, b, c));
return 0;
}


Am I any wrong, senpai? I'm just learning, will appreciate any help and advices ^^
>>
public static double average(int num1, int num2, int num3) {
return (num1+num2+num3)/3;
}
>>
>>55484925
5 print "type 3 integers, ":
7 print "separated by newlines"
10 input a%, b%, c%
20 print (a%+b%+c%)/3

ezpz

>>55485227
there's zero risk here
sure, if this was anything other than a toy program, you'd have to look at that
I've been doing these in C64 basic entirely because they're toy programs.

as an aside, my implementation would look like
10 rem average 3 ints (p1% to p3%)
12 rem result in retv
15 retv = (p1%+p2%+p3%)/3:return

as an unadorned subroutine, comments merely noting the calling/return conventions
>>
>>55490254
why do you use input requests you nigger, just define a function with parameters
>>
You are all cucks.

>using built-in add functions

Someone write a version that uses only binary and and or functions (like simulating a fast adder on a FPGA). I dare you. For max speed.
>>
what happened to good old command line arguments, anons?

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
unsigned int i;
int num;
if (argc < 3)
return EXIT_FAILURE;
num = 0;
for (i = 1; i <= 3; ++i)
num += atoi(argv[i]);
printf("%g\n", num / 3.0f);
return EXIT_SUCCESS;
}
>>
>>55484925
python
lambda x,y,z:(x+y+z)/3
>>
def dicks(a): return sum(a)/len(a)
>>
File: 1461799140575.png (48 KB, 188x244) Image search: [Google]
1461799140575.png
48 KB, 188x244
>>55484925



fun1 <- function(x, y, z) {
c <-c(x, y, z)
print(mean(c))
}


fun1(25, 2, 25)

>>
>>55485747
>>55485747
Lel
>>
>>55485617
iostream is for losers
>>
[a,b,c].reduce((avg, n, array) => avg + n / array.length, 0);
>>
=AVERAGE(A1,A2,A3)
>>
>>55488072
>>55488600
... her?
>>
import add    from 'add-operation'
import divide from 'div-operation'

export default ([n1, n2, n3]) => divide(add(add(n1, n2), n3), 3)
>>
>>55484925
#!/bin/bash
echo $((((3+4)+5)/3))
>>
>>55485572
>3 integer args to main declared globally
wtf made you think this would work?
>>
>>55484925
int main() {
a = 5;
b = 8;
c = 21;
return (a+b+c)/3;
}
>>
>>55486099
lmao what nigga
just compute and return the average of the 3 ints
>>
>>55487320
I actually like seeing simple programs implemented in languages I don't know.
>>
function avg(a,b,c) {
return (a+b+c)/3;
};
>>
int avg3nums (void) {
/* computes average of three numbers */
return (0 + 0 + 0) / 3;
}
>>
>>55493122
Yes
>>
File: 1462609598983.png (162 KB, 627x311) Image search: [Google]
1462609598983.png
162 KB, 627x311
>>55488072
>aesthetic
What the fuck are you talking about? Her face is massive. This is an /fa/ face.
>>
>>55484951
It's appealing to me like how Steve Buscemi, another common HBO actor, has an " ugly" face
>>
#include <iostream>

using namespace std;
int main() {

double j = 0;
double k = 0;
for(int i = 1; i < 4; i++)
{
cout << "Give " << i << " number: \n";
cin >> k;
j = j + k;
}
cout << "Average of 3 numbers is: " << j/3;

}
>>
>>55485350
i guarantee you have high blood pressure
>>
No Haskell solutions?
>>
File: 335.jpg (38 KB, 512x384) Image search: [Google]
335.jpg
38 KB, 512x384
from statistics import mean
numbers = [int(x) for x in input().split()]
print(mean(numbers))
>>
>>55484925
how do I acquire gf of this caliber /g/?
>>
>>55484925

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

Dit I miss something?
>>
PRINT (a%+b%+c%) DIV 3
>>
>>55485869
Mah nigga
>>
File: 329.png (67 KB, 200x200) Image search: [Google]
329.png
67 KB, 200x200
>>55496819
>int
>>
>>55484925
avg←{ (+⌿⍵) ÷ ≢⍵ }
>>
var avg = (a,b,c) => {return [a,b,c].reduce((m,i) => {return m+i}, 0)/3}
>>
>>55488161
how safe is this?
>>
>>55484925
What's an integer?
>>
>>55484925
Prolog
?- read([A,B,C]), Avg is (A+B+C)/3.
|: [2,567,7376853588].
A = 2,
B = 567,
C = 7376853588,
Avg = 2458951385.6666665.
>>
(lambda (x y z) (/ (+ x y z) 3))
>>
Straightforward way
>from statistics import mean
>l = [1, 4, 88]
>print mean(l)

Tricky one
>l = [1, 4, 88]
>print sum(l)/(len(l)*1.0)
>>
File: 1.png (13 KB, 652x316) Image search: [Google]
1.png
13 KB, 652x316
>>55484925
ABAP, even comes with ui:
REPORT Z_AVG.

DATA avg TYPE i.

PARAMETERS:
a LIKE avg,
b LIKE avg,
c LIKE avg.

START-OF-SELECTION.

avg = ( a + b + c ) / 3.

WRITE: 'The average is', avg.
>>
function ans = tripleaverage(a,b,c)
ans = (a+b+c)/3;
>>
public double avg(int... args){
int sum=0;
for(int arg : args)
sum+=arg;
return (double)sum/args.length;
}
>>
>>55496819
avg(1,3,4) will return 2, but it is 2 2/3, use doubles.
>>
Swift
func average(firstInt: Int, secondInt: Int, thirdInt: Int) -> Double {
let sum = Double(firstInt + secondInt + thirdInt)
let average = sum / 3

return average
}
>>
File: 1466555714545.png (2 MB, 1300x1619) Image search: [Google]
1466555714545.png
2 MB, 1300x1619
>>55485367
Bit of a smarmy douchebag aren't you? I bet you're about as smart as a dungheap, and your code is just as bad. Only the most pathetic code-monkey programmers have the autism and lack of social skill to lash out at people on the internet for such inane reasons like that.
>>
>>55487537
>t. guy that can't even code
>>
>>55498881
>Only the most pathetic code-monkey programmers have the autism and lack of social skill to lash out at people on the internet for such inane reasons like that.
But this is 4chan, so it's OK.
>>
>>55485747
That's how it's done, /thread.
>>
>>55484925
float IntAverage(int *ints, int numInts) {
int sum=0;
for(int i=0; i<numInts; i++) {
sum+=ints[i];
}
return ((float)sum) / ((float)numInts);
}

int main() {
int ints[]={1, 2, 3};
return IntAverage(ints, 3);
}
>>
>>55485230
here's mine
#include <iostream>

int main() {
int x, y, z;
std::cin >> x >> y >> z;
std::cout << (x+y+z)/3.0 << std::endl;
return 0;
}
>>
File: 1428106363775.jpg (11 KB, 399x382) Image search: [Google]
1428106363775.jpg
11 KB, 399x382
>>55485747
>the stock python app
the stock python app
>the stock python app
the stock python app
>>
>>55484925
int answer = ((1+2+3)/3);
>>
public decimal Avg(params int[] nums)
{
var output = 0m;
for (int i = 0; i < nums.Length; output += nums[i++]);
return output / nums.Length;
}
>>
public double average(List<int> listOfIntegers)
{
return listOfIntegers.Average();
}


rate my code /g/
>>
>>55500084
your is shit <<
>> public void main()
{
console.WriteLine(" fuck nigga");
console.Realine();
}
>>
>>55500084
seems to defeat the purpose
>>
>>55485816
Java uses it, it makes the variable an unchangeable constant
>>
Is this thread satirizing the simplicity of all of these threads, or is OP not trying anymore? Also, why do I get 420 for a captcha so often?
>>
input i1, i2, i3
doodooo = i1+i2+i3
doodooo /= 3
shoot doodooo out -> output pipe 1
finish global
>>
PYTHON ONE LINER WHERE
>>
Who is this spunk chipmunk?
>>
>>55487274
Here is another version in FASM asm:
format PE console
entry start

include 'win32a.inc'
section '.text' code executable
start:
mov eax, 0
add eax, [a]
add eax, [b]
add eax, [c]
mov [result], eax
mov edx, 0
div [total]
cinvoke printf,formatstring, eax
invoke Sleep,-1

formatstring db "%d",13,10,0
section '.data' data readable writable
a dd 10
b dd 20
c dd 30
total dd 3
result dd 0
section '.idata' import data readable

library msvcrt,'msvcrt.dll',\
kernel32,'kernel32.dll'
import msvcrt,printf,'printf'
import kernel32,Sleep,'Sleep'
>>
I'm an out of practice second year CS student
forgive me
int main()
{
int a;
int b;
int c;
int avg;
cout << "\nEnter a: " ;
cin >> a;
cin.ignore(100, '\n');
cout << "\nEnter b: " ;
cin >> b;
cin.ignore(100, '\n');
cout << "\nEnter c: " ;
cin >> c;
cin.ignore(100, '\n');

avg = (a + b + c) / 3;
cout << "Average: " << avg << endl;

return 0;
}



I'm sure there are better ways.
>>
 public int avg(int a, int b, int c){

int ret = (a+b+c)/3;
return ret;
}

>>
select avg(a) from (select 1 a union all select 3 a union all select 8 a)tmp;
>>
float avg(integer a,integer b,integer c){
return (a+b+c)/3.0;
}

default{
state_entry(){
llListen(1,"",NULL_KEY,"");
}listen(integer channel,string name,key id,string msg){
list words = llParseString2List(msg,[" "],[]);
if(llGetListLength(words)!=3) return;
if(llList2Integer(words,0)==0 || llList2Integer(words,1)==0 || llList2Integer(words,2)==0) return;
llInstantMessage(id,(string)avg(llList2Integer(words,0),llList2Integer(words,1),llList2Integer(words,2)));
}
}


kill me
>>
>>55501446
Other method, now with comments so you can understand it!
format PE console
entry start

include 'win32a.inc'
section '.text' code executable
start:
mov eax, 0 ;tempA = 0
mov ebx, 0 ;i = 0
mov ecx, 0 ;tempB = 0

sum:
mov eax, [array + 4 * ebx] ;tempA = numbers[i]
sub eax, [result] ;tempA = numbers[i] - m
mov ecx, ebx ;tempB = i
add ecx, 1 ;tempB = i + 1
mov edx, 0 ;clear for div
div ecx ;tempA /= tempB
add [result], eax ;m += tempA
add ebx, 1 ;++i
cmp ebx, 3 ;if(i < 3)
jl sum ;then goto sum
cinvoke printf,formatstring, [result] ;print average
invoke Sleep,-1

formatstring db "%d "
section '.data' data readable writable
array dd 10
dd 20
dd 30
total dd 3
result dd 0
section '.idata' import data readable

library msvcrt,'msvcrt.dll',\
kernel32,'kernel32.dll'
import msvcrt,printf,'printf'
import kernel32,Sleep,'Sleep'
>>
>>55501446
>mov eax, 0
> add eax, [a]
why not just mov eax, [a] ?
>>
for n in 5 10 16; do echo $n ; done | awk '{tot+=$1;cnt++}END{print tot/cnt}'
>>
>>55502553
It has been a while since I have programmed in ASM lol. even my second one is a bit rusty. Thanks for pointing that out T_T
>>
>>55485366
They're delicious pancakes.
>>
Written in the best language ever

package main

import "fmt"

func main() {

var noOne float32
var noTwo float32
var noThree float32

fmt.Println("Please enter the three numbers that you would like to average out")
fmt.Scan(&noOne)
fmt.Scan(&noTwo)
fmt.Scan(&noThree)
average := noOne + noTwo + noThree
fmt.Println("The average of these three numbers is")
fmt.Println(average / 3)
}
>>
>>55484925
this one averages as much integers as you like, even 3
char delimiter = ' ';
string input = Console.ReadLine();

string[] values = input.Split(delimiter);
int[] val = values.Select(x => int.Parse(x)).ToArray();

int tmp = 0;
for (int i = 0; i < val.Length; i++)
{
tmp += val[i];
}

double vals = tmp;
double res = vals / val.Length;

Console.WriteLine(res);
Console.ReadKey();
>>
>>55490978
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int num;
if (argc > 3) {
num = atoi(argv[1]) + atoi(argv[2]) + atoi(argv[3]);
printf("%g\n", num / 3.0f);
}
return 0;
}


I simplified it for you, anon.
>>
int main() {return 0;} 

The exit code is the average of 0, 1 and -1.
>>
>>55484925
Apparently the girl in OP's pic is 34 years old
>>
>>55484951
I like her for her eyes and her smirk. Can take or leave the rest.
>>
File: 1452285433301.png (271 KB, 322x568) Image search: [Google]
1452285433301.png
271 KB, 322x568
>mfw most answers are vulnerable to overflow
Try averaging 2147483646, 1 and 3(if you're using signed ints).

Here's the proper answer:
static double ProperAverage(List<int> list)
{
double prev = list.First();
int index = 1;

foreach(var num in list.Skip(1))
{
prev = ((prev * index) + num) / (index + 1);
index++;
}

return prev;
}
>>
Anyone doing JS and not doing this, know jack shit about JS.

var avg = (a, b, c) => (a + b + c) / 3;
>>
File: Burn.png (5 KB, 62x62) Image search: [Google]
Burn.png
5 KB, 62x62
>>55504876
mfw this anon can't fucking read and thus misses the part where it is clearly stated three fucking integers, specifically.
>>
Post her boobs and I will give you your program
>>
>>55504938
What's the problem? My function does more than what's required? Well, can it still do what it was asked for? The answer is yes, so shut your whore mouth.
>>
>>55484925
numbers = [1, 2, 3]
sum(numbers) / float(len(numbers))
>>
f(x::Vector{}) = sum(x) / length(x)
>>
File: 67b22c0198e1f90c617dc734e7e88288.jpg (790 KB, 2400x3600) Image search: [Google]
67b22c0198e1f90c617dc734e7e88288.jpg
790 KB, 2400x3600
>>55484951
the fuck other way around for me
>>
Niggers
>>
>>55505286
actually, it does less. As a *program* to get an average of three integers was asked for, yet you only provided a function.
>>
>>55484925
>averages 3 integers
not well defined problem
>>
>>55500286

thatsTheJoke.jpg
>>
>>55504265
8 spaces, really?
>>
>>55484925
(a+b+c)/3

/thread.
>>
>homework thread
>200+ replies
>>
avgThree :: Int -> Int -> Int -> Int
avgThree x y z = (x + y + z) / 3
>>
return (a + b + c ) / 3

cast to float if desired

...why is this a thread?
>>
>>55505658
>defining one tab as anything other than being 8 spaces wide
you don't spend a lot of time programming, do you?
>>
>>55485177
>a lot of people find that really attractive.
Do you have a source on this claim? Or are you just making shit up to strengthen your opinion? Which is wrong, btw.

She has a shit face, average tits but nice hair.
>>
public double Average(double a, double b, double c)
{
return (a + b + c)/3;
}
>>
>>55505581
Joke's on you, my compiler is tweaked to use ProperAverage as the entry point, casts arguments to a List<int> and prints the return value of the entry point to stdout
>>
int main () {
return (1+2+3)/3
}
>>
File: mdc.jpg (102 KB, 650x650) Image search: [Google]
mdc.jpg
102 KB, 650x650
>>55505926
>definitely not an after-thought once I pointed it out

wew, lad
>>
>>55505884

>Which is wrong, btw.

Facts can be wrong, statistics can be wrong, but opinions can't.

And she is quite attractive, especially to neckbeards and basement dwellers like you which you'll of course deny fervently but considering how much you've jerked off to her picture as well as your own post I'd be surprised if you could get one coherent thought posted as a retort.

But give it your best shot, son, we're waiting.

>stupid fucking people will be the death of us all
>>
File: What_is_it.jpg (252 KB, 1200x856) Image search: [Google]
What_is_it.jpg
252 KB, 1200x856
>>55495142
>tfw wen you wanted to see bait continue
>>
>>55506485
>Facts can be wrong, statistics can be wrong, but opinions can't.
It is my opinion that you're retarded
>>
>>55484951
I compiled this and it works
>>
>>55484925
let arr = [1,2,3];
let arrAvg = arr.reduce((a,b)=>a+b)/arr.length;
>>
>>55505836
of course not, there is no need to be an actual code monkey. why 8 though?
>>
>>55485463
You forgot the hasOwnProperty check you dipshit
>>
>>55508599
That is disgusting. What is it?
>>
>yfw none of answers posted are correct
try averaging 4294967295, 4999 and 1 faggots
>>
>>55508640
Javscript
>>
>>55508674
Mine checks out retard.
>>
>>55508674
Youre assuming that all languages have the same bit size...
>>
>>55508605
once you spend 20+ consecutive hours programming, you'll understand.
>>
>>55505526
Bleh.
>>
>>55484925

section .text
global _start

_start:
mov edx, int0

mov ecx, int1
add edx, ecx

mov ecx, int2
add edx, ecx

div edx, 3

section .data
int0 DQ 123
int1 DQ 456
int2 DQ 789


your returnvalue is in edx
>>
>adding the numbers
Arithmetic overflow.
return (int)(a/3.0+b/3.0+c/3.0);
>>
>>55484925
avg(A,B,C,R) :- R is (A + B +C)/3 .
>>
>>55488352
>impliying result is integer using parseInt instead parseFloat
>not using a more elegant and compact approach knowing that * operators cast to number.

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

Seriously people?
>>
>>55484925
(a+b+c)/3
>>
>>55510020
yes, and tomorrow will be average of 4 numbers, deal with it.
>>
>>55485166
I would label that array so, instead of /3 it would be /array.length. But to each his own.
>>
Is nobody gonna do it in brainfuck?
>>
>>55485522
Python has arbitrarily long integers senpai
>>
>>55508988
i've asked some professional programmers and they couldn't tell me (though they are javababbies)
Thread replies: 255
Thread images: 18

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.