[Solved] C# get position of a character from string

string aS = “ABCDEFGHI”; char ch=”C”; int idx = aS.IndexOf(ch); MessageBox.Show(string.Format(“{0} is in position {1} and between {2} and {3}”, ch.ToString(), idx + 1, aS[idx – 1], aS[idx + 1])); This wont handle if your character is at position zero and some other conditions, you’ll have to figure them out. 2 solved C# get position … Read more

[Solved] How does #define carries the function name in c?

C preprocessor macros simply do text replacement. They have no semantic awareness of your program. This: #include <stdio.h> #define x printf(“%s”, f); int main() { char* f = “MAIN”; printf (“Hello World”); x; return 0; } Becomes: #include <stdio.h> int main() { char* f = “MAIN”; printf (“Hello World”); printf(“%s”, f);; return 0; } Please … Read more

[Solved] How can i sort a string with integers in c++?

Here it’s done with std::sort from the header algorithm #include <iostream> #include <string> #include <algorithm> #include <vector> int main(){ std::vector<std::string> nums{ “922003001020293839297830207344987344973074734”, “766352786207892397340783784078348747606208602”, “182823068326283756515117829362376823572395775” }; std::cout << “unsorted: ” << std::endl; for (auto i : nums){ std::cout << i << std::endl; } std::sort(nums.begin(), nums.end()); //sort it std::cout << “\nsorted: ” << std::endl; for (auto i … Read more

[Solved] nested for loops now not working

To answer your second part of the question, with the assumption that every round the health will decrease till 1 player hits 0. (Because the way you are implementing it now, is that every time the inner For-loop is done, you reset the health of both wizard and sorceress, therefore making this requirement useless) Declare … Read more

[Solved] factorial giving wrong answer

I think the reason why you are getting “random” numbers is because you haven’t initialized the carry variable. In the for loop, you are adding the un-initialized value of carry to the array which will cause undefined results. solved factorial giving wrong answer

[Solved] C++ total beginner needs guidance [closed]

I have not spent effort in trying to understand your algorithm, but at first glance it looks more complicated than it should be. From my understanding of the problem, there are 3 possibilities: the totals of the upper halves and the lower halves are already even (so nothing needs to be done) the totals of … Read more

[Solved] How does #define carries the function name in c?

Introduction #define is a preprocessor directive in the C programming language that allows for the definition of macros. It is used to replace a function name with a predefined value. This is useful for creating constants, as well as for creating short-hand versions of commonly used functions. By using #define, the programmer can save time … Read more