Cengizhan
In c/c++
So, basic algorithm is how many squares in N*N square? N * N + (N-1) *(N-1) + ... 1 * 1 -> Calculate in C++.
Cengizhan
that pic is complete question
Oh, really? I did not see, sorry.
S@IF
what is best algo for that
Cengizhan
I guess, for loop is the best algo. Whenever I write, it solves my problems.
S@IF
my mean equation
S@IF
i used counter += pow(n, n)
Cengizhan
No, there is better way.
S@IF
could u solve it.
Cengizhan
counter = (n * (n+1) * (2n + 1)) / 6
S@IF
with complete code
S@IF
how could u think with that angle means how u got...
S@IF
i tried so many to solve but i never think with such extend
S@IF
means how u got that algo
Cengizhan
I have a bronze medal from math olympics.
S@IF
i know some about this concept but never get into practical
S@IF
hey u solve with that concept.. or just directy got
S@IF
or understand algo
S@IF
okay.. thank you😊
Anonymous
i know some about this concept but never get into practical
Come to OT. I have a famous story related to this
Anonymous
;-; k
sree nandhan
In c/c++
I am confused ... If size of the board is N then no.of box must he N*N right ? ... Sry if i am being stupid here ...
sree nandhan
Oh. Okay 👍
sree nandhan
Thanks .
S@IF
could u just write the code.. it would help me
S@IF
it's okay... thank you for that all explanation
Anonymous
Guys I have a question... is It ok to call only one parameter of a function? (I'm programming on a textbook) example: ---------------- procedure container ( value1, value3, value5 as Integer){ } procedure test{ Int local_container Int taker = container (value5 => local_container) }
Anonymous
Or should I create a separated package that would contain value1 to value5 and call it externally?
Anonymous
I'm new to programming. I looked for it, but: + I found things about sql Because I didn't knew how look to express my problem. So that why I went to human to help me. Anyway, thank you
Anonymous
We want to display rectangles ( 4 cm width * 3 cm hieght). The input is the number of the required rectangles. Display them as the following: Three rectangles in each row. Each row will be 14 cm because we separate rectangles by 1 cm and so the rows. It must be solved by a mathematical equation to display the rectangles automatically.
Anonymous
I tried this but it's not good enough for this one: #include <iostream> using namespace std; int main() { int rect; cin>>rect; int blocks, single, fill; single = rect%3; blocks = rect/3; fill = 14; for (int y=0; y<blocks+single; y++){ if (y==blocks) { fill = (single*4)+(single-1); if (single>1) single--;} for (int i=0; i<3; i++){ for (int j=0; j<fill; j++){ if (j==4||j==9) {cout<<' '; continue;} cout<<'*';} cout<<'\n'; } cout<<'\n'; } }
Xcix
I need help in trying to solve this..It's actually in C programming..Can somebody please help me?
Anonymous
Why are you struggling? What do you expect others to help you with exactly?
I want it solved mathematically. The person who talked about it said that it is enough for 9th grade students to solve it mathematically without any knowledge of programming.
Xcix
3*(x*x*x)-5*(x*x)+6
thank you very much..I tried it and it worked
Anonymous
Halo guys
Anonymous
Hello, I want to do a little test I wrote a little program in c++, it's just a simple number guessing game I'm trying to follow programming best practices but I don't know if I did it the right way (I mean, it looks fine to me but I have 0 confidence because of my lack of experience) Can I send the .cpp file here, so you can check it and suggest changes and improvements in my way of witting code?
Anonymous
Ya sure
Anonymous
Here it is 😅
Anonymous
I am a beginner start from zero about programming,can u guys help me please Its so much thanks for u all
Anonymous
I am a beginner start from zero about programming,can u guys help me please Its so much thanks for u all
Well, there's a cool website called: learncpp.com (no joke) I'm learning with it
Anonymous
no problem
Anonymous
Its my first time trying programming,i try it from the bookpdf,but always error,may i mistake?
Anonymous
Its my first time trying programming,i try it from the bookpdf,but always error,may i mistake?
Compare it with a hello world program and try to find what's wrong
Tekipeps
what book is recommended to learn cpp from beginner to advanced please
Brown
How do I change a numbers precision by input number ? Ex : If I want n digits after decimal. I want this n to be taken from input, scanf or something. How do I do it ?
Monday Morning
printf("%.nf",var_name);
I thought this would work. I was mistaken
vinícius*
float pi = 3.1415926535897; int decimals = 2; printf("%.*f", decimals, pi);
vinícius*
that'd print out 3.14
Monday Morning
Works like a charm.
vinícius*
Here it is 😅
looks fine :D
Anonymous
looks fine :D
thank you :D
vinícius*
only 'problem' is the weird usage of list initializers
vinícius*
like in int number{generate_random_int()}; int guess{};
vinícius*
it's definitely not wrong, but usually you'd do something like
vinícius*
int number = generate_random_int(); int guess;
vinícius*
like in int number{generate_random_int()}; int guess{};
the only downside to this is that it only exists after C++11, AFAIK
Anonymous
the only downside to this is that it only exists after C++11, AFAIK
Yeah, that's why I used them, I saw it in the course I'm following And they said that this "brace initialization" was created in c++11
vinícius*
well
Anonymous
Is it a little overkill? They told me the same thing in another programming group haha
vinícius*
it's not like anyone still cares about C++03 and older, so no problem
Anonymous
oh, well
vinícius*
Does it work on C ?
I don't think so but I'm not sure
Anonymous
I think it doesn't, let me check
vinícius*
test.c: In function ‘main’: test.c:4:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token float pi{3.1415926535897};
vinícius*
nope
Brown
the only downside to this is that it only exists after C++11, AFAIK
There is a set precision function in c++ for cout .
Anonymous
Holy errors batman (I added some suggested modifications)