Cristi
This is my code:
Cristi
The problem is that when I write "printf("%d", p)" outside the if function, it gives me a completely different result, but if I write the same thing inside the if function, then everything is correct
Cristi
#include<stdio.h> #include<time.h> #include <stdlib.h> #include <math.h> int main () { int cont, s, p, med_geo; int i, r, t, k, h, z, x; int Tablou[6][9]; srand(time(NULL)); for (i = 0; i < 6; i++) { for (x = 0; x < 9; x++) { Tablou[i][x] = rand() % 100 - 50; } } printf("\n"); printf("\nTabloul initial: \n"); for (int q = 0; q < 6; q++) { for (int w = 0; w < 9; w++) { printf("%d\t", Tablou[q][w]); } printf("\n"); } for (r=0;r<6;r++){ s = 0; p = 1; cont = 0; for(t=0;t<9; t++){ if (Tablou[r][t] <0 ){ s = s + Tablou[r][t]; } else{ p = p * Tablou[r][t]; cont++; } printf("%d\n", p); } } }
Cristi
Can someone help me ?
Dima
format your code
Cristi
format your code
What do yo mean by that ?
Hadaward 'Solly'
What do yo mean by that ?
code in a structured way so it can be read even by a blind person.
Cristi
code in a structured way so it can be read even by a blind person.
I am new in programming, could you please explain what do you mean by this ? What is wrong with my code ?
Hadaward 'Solly'
prob just the spacing. Also, try to select your code after pastaing in telegram and select to make it monospace for readability sake
Hadaward 'Solly'
like this
Hadaward 'Solly'
int main (){ int fresh, outta, oven; for (expr; expr; expr) { do { // Stuff } while (expr); } return 0; }
Hadaward 'Solly'
and dont forget the return 0; if you are using a descent compiler
Hadaward 'Solly'
now that i took a closer look, if you indent it better, you'd prob find out why your print is in the wrong place
Hadaward 'Solly'
also %d is not good since your geometric mean might be float (real)
Hadaward 'Solly'
plus by definition (context) you need to do square number of elements to get the actual mean
Hadaward 'Solly'
so take a look again and good studies
Anonymous
and dont forget the return 0; if you are using a descent compiler
this is unnecessary. reaching the } that terminates the main function returns a value of 0.
Hadaward 'Solly'
Anonymous
🤷
Hadaward 'Solly'
🤷‍♂️
Cristi
how to raise a number to a real power in C?
Nameful
std::pow?
Nameful
oh wait
Cristi
but in C?
Cristi
for example: pow(2, 1/cont) where cont is a random float number between 1 and 6
Cristi
That doesn't work
Cristi
I get error
Cristi
undefined reference to `pow' collect2: error: ld returned 1 exit status make[3]: *** [CMakeFiles/untitled8.dir/build.make:104: untitled8] Error 1 make[2]: *** [CMakeFiles/Makefile2:96: CMakeFiles/untitled8.dir/all] Error 2 make[1]: *** [CMakeFiles/Makefile2:103: CMakeFiles/untitled8.dir/rule] Error 2 make: *** [Makefile:138: untitled8] Error 2
Manav
Yes, unless you are following C89 standard or previous ones
professor
I am making a crawler using a rss and other stuff, but some urls / parsers bandwith is slow e.g china or russia from US servers what is the average time before timeout? 60 or 90?
Hadaward 'Solly'
but in C?
sadly, people think it's a great idea to standardize return omission. So go ahead and have fun not typing 9 extra characters in your code. Did you manage to use exponential function in C?
Hadaward 'Solly'
#ot
ברני
can someone explain me why in visual studio I must define Size of array and can't do the size in the main function? e.g: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #define SIZE 5 int main() { int myGrades[SIZE]; myGrades[0] = 10; myGrades[1] = 15; myGrades[2] = 20; myGrades[3] = 25; myGrades[4] = 30; for (int i = 0; i < SIZE; i++) printf("%d ", myGrades[i]); return 0; }
ברני
and in other compiler I can do this: #include <stdio.h> #include <stdlib.h> int main() { int size = 5; int myGrades[size]; myGrades[0] = 10; myGrades[1] = 15; myGrades[2] = 20; myGrades[3] = 25; myGrades[4] = 30; for (int i = 0; i < size; i++) printf("\n%d", myGrades[i]); return 0; }
olli
because VLAs are an optional feature and are not required. According to ISO C the size of the array shall be a compile time constant
Merazi
/report
Ибраги́м
/ban
Talula
Like SizeX or something.
Manav
ofc
Then why do you say its unfortunate to standardize return omission?
Hadaward 'Solly'
It's important to emphasize the procedural paradigm before anything, so we people understand computability in a fundamental level
Hadaward 'Solly'
not from the get go, but getting the importance of process communication through these details
Hadaward 'Solly'
abstraction is good. OO is neat but let the novices that need to see C in the start get the low level feeling of things. Hiding too much is pythonish
Manav
abstraction is good. OO is neat but let the novices that need to see C in the start get the low level feeling of things. Hiding too much is pythonish
I don't follow your arguement, you want to keep everything unnecessarily verbose? This could be used to bring back fun(void) for a function which doesn't take any argument or removing default from switch statement.
Hadaward 'Solly'
9 "extra" key strokes are verbose?
Hadaward 'Solly'
you could just argue that every other feature and aspect in C already is enough for the procedural learning. I'll just assume it's a small pedagogic divergence :)
Hadaward 'Solly'
saying that's verbose is trying hardish
Manav
saying that's verbose is trying hardish
Nah, it's you making a big deal out of an understood default behavior, which was omitted out for good
Manav
You can just tell someone, if they ask, why doesn't main return anything when I see an int in its definition, That it returns 0 by default and we don't write it because it's a default behavior
Hadaward 'Solly'
why would a youngster just started ask directly such question is beyond me
Hadaward 'Solly'
but suit yourself, i think that works in your education centre
Manav
why would a youngster just started ask directly such question is beyond me
Why would you not tell something this basic to a youngster is beyond me
Hadaward 'Solly'
probably different cultures. It's safe to assume here, that even if we tell procedures will inevitably have return values, they won't pose such question even when perceiving main as such.
Hadaward 'Solly'
since it's that obvious for your pupils, i see absolutely no problem in your statement
Manav
since it's that obvious for your pupils, i see absolutely no problem in your statement
I am not a teacher btw. Now that I think about it, yeah, it could cause some confusion amongst absolute beginners.
Hadaward 'Solly'
it's understandable that our experienced coders here would find the need to type return outrageous. There's definitely more important things to do in that stage of career.
Harsh
it's understandable that our experienced coders here would find the need to type return outrageous. There's definitely more important things to do in that stage of career.
I hold kinda similar take. For starters, there should be exposure to data types, function returns. That helps in long run, making our brain a debugger. Being intuitive about coding.
Hrithik.41
Hrithik.41
Anyone help me with this
Hrithik.41
Hrithik.41
Hrithik.41
I calculated the sum in book
Hrithik.41
But the value of compound interest annually was coming wrong in program
Hrithik.41
Hrithik.41
It should be 205299.38
Vlad
/ ban turbo C in 2020 is illegal
Hrithik.41
/ ban turbo C in 2020 is illegal
Ok bro I'll do in codeblocks
Anonymous
/report screen photo + outdated compiler
Hrithik.41
But 1st tell me solution
olli
But 1st tell me solution
use double, float is not accurate enough
Vlad
But 1st tell me solution
I'm pretty sure you got formulae wrong
Vlad
use double, float is not accurate enough
I don't think that float is an issue in this case