Pavel
/report It is posted here three times by you, and you've been asked not to repost the same thing that is barely related with the topic of the group. Can you stop it?
Rohan
I resolved this problem @Correctmaninwrongplace you are right I'm trying to print elements of object by mistake..
Anonymous
Share your code and ask specific question.
#include <stdio.h> int main() { //num: to store number entered by the user int num; //count: to count number of digits int count = 0; //i: for looping int i; //for calculating sum int sum = 1, sum2 = 0; //for storing individual digits int d = 1; //tcount, tnum: temporary containers for num and count's original values as it is goimg to be modified in our program int tcount, tnum; //Ask the user to input the number printf("Enter a number: "); scanf("%d", &num); //store the original value of 'num' in temporary varible i.e 'tnum' tnum = num; //Checking the number of digits in the user input for(i = 0; num != 0; i++) { num = num / 10; count = count + 1; } //reassign the original value of num to tnum as it was modified in the above loop num = tnum; tcount = count; //get the number of digits in the input, now raising the power total number to each digits to check whether it is armstrong number or not //eg: if the entered number has 3 digits, raise power 3 to each digits and add them //if it has 4 digits, then raise power 4 to all and sum them printf("Before: count: %d, Sum: %d\n\n", count, sum); for(num; num != 0; num = num / 10){ d = num % 10; for (i = 0; i < count; ++i){ sum = sum * d; printf("Sum in every loop: %d\n", sum); sum2 += sum; //sum = sum + (d * d * d); } } printf("%d \t %d\t%d\n", sum, tnum, sum2); if(tnum == sum) printf("%d is armstrong number", tnum); else printf("%d is not armstrong number", tnum); return 0; } It is not returning expected results.
Rohan
But how is it of type void?
void bubbleSort(int arg);
correctmaninwrongplace
#include <stdio.h> int main() { //num: to store number entered by the user int num; //count: to count number of digits int count = 0; //i: for looping int i; //for calculating sum int sum = 1, sum2 = 0; //for storing individual digits int d = 1; //tcount, tnum: temporary containers for num and count's original values as it is goimg to be modified in our program int tcount, tnum; //Ask the user to input the number printf("Enter a number: "); scanf("%d", &num); //store the original value of 'num' in temporary varible i.e 'tnum' tnum = num; //Checking the number of digits in the user input for(i = 0; num != 0; i++) { num = num / 10; count = count + 1; } //reassign the original value of num to tnum as it was modified in the above loop num = tnum; tcount = count; //get the number of digits in the input, now raising the power total number to each digits to check whether it is armstrong number or not //eg: if the entered number has 3 digits, raise power 3 to each digits and add them //if it has 4 digits, then raise power 4 to all and sum them printf("Before: count: %d, Sum: %d\n\n", count, sum); for(num; num != 0; num = num / 10){ d = num % 10; for (i = 0; i < count; ++i){ sum = sum * d; printf("Sum in every loop: %d\n", sum); sum2 += sum; //sum = sum + (d * d * d); } } printf("%d \t %d\t%d\n", sum, tnum, sum2); if(tnum == sum) printf("%d is armstrong number", tnum); else printf("%d is not armstrong number", tnum); return 0; } It is not returning expected results.
the inner for can be change by just 1 line of the correct code, you have it there, so uncomment that line and delete the loop
Anonymous
the inner for can be change by just 1 line of the correct code, you have it there, so uncomment that line and delete the loop
That line only checks for 3 digit code. And I am making it to check any number of digits, so I had commented it for reference only. So, I needed another for loop to raise "count" power to the sum, which is that.
01000001011011010100000101101110
#include <stdio.h> int main() { //num: to store number entered by the user int num; //count: to count number of digits int count = 0; //i: for looping int i; //for calculating sum int sum = 1, sum2 = 0; //for storing individual digits int d = 1; //tcount, tnum: temporary containers for num and count's original values as it is goimg to be modified in our program int tcount, tnum; //Ask the user to input the number printf("Enter a number: "); scanf("%d", &num); //store the original value of 'num' in temporary varible i.e 'tnum' tnum = num; //Checking the number of digits in the user input for(i = 0; num != 0; i++) { num = num / 10; count = count + 1; } //reassign the original value of num to tnum as it was modified in the above loop num = tnum; tcount = count; //get the number of digits in the input, now raising the power total number to each digits to check whether it is armstrong number or not //eg: if the entered number has 3 digits, raise power 3 to each digits and add them //if it has 4 digits, then raise power 4 to all and sum them printf("Before: count: %d, Sum: %d\n\n", count, sum); for(num; num != 0; num = num / 10){ d = num % 10; for (i = 0; i < count; ++i){ sum = sum * d; printf("Sum in every loop: %d\n", sum); sum2 += sum; //sum = sum + (d * d * d); } } printf("%d \t %d\t%d\n", sum, tnum, sum2); if(tnum == sum) printf("%d is armstrong number", tnum); else printf("%d is not armstrong number", tnum); return 0; } It is not returning expected results.
In which test cases it isn't giving expected output?
Anonymous
In all cases, it shows wrong result. the result shoes there's something error in the loop, so I can't figure it and fix it. Can you figure it and fix it☺️
correctmaninwrongplace
i would use pow
correctmaninwrongplace
having the number of digits before starting
Modestas
y=1+x+(x^2)/2!+(x^3)/3!+(x^4)/4! How this solve in C++ ? is it possible?
Modestas
Of course it is possible.
Maybe available any equations converter to C++ programming language online?
Толиббек Дилмуродов 🥂
Hello every body
Asdew
Maybe available any equations converter to C++ programming language online?
I think you're supposed to do it yourself as you have to do it.
Толиббек Дилмуродов 🥂
Do you have any best books for C#?
Толиббек Дилмуродов 🥂
Or C++
Толиббек Дилмуродов 🥂
Or any channels?
Толиббек Дилмуродов 🥂
Or any channels?
???????????????
01000001011011010100000101101110
#include <stdio.h> int main() { //num: to store number entered by the user int num; //count: to count number of digits int count = 0; //i: for looping int i; //for calculating sum int sum = 1, sum2 = 0; //for storing individual digits int d = 1; //tcount, tnum: temporary containers for num and count's original values as it is goimg to be modified in our program int tcount, tnum; //Ask the user to input the number printf("Enter a number: "); scanf("%d", &num); //store the original value of 'num' in temporary varible i.e 'tnum' tnum = num; //Checking the number of digits in the user input for(i = 0; num != 0; i++) { num = num / 10; count = count + 1; } //reassign the original value of num to tnum as it was modified in the above loop num = tnum; tcount = count; //get the number of digits in the input, now raising the power total number to each digits to check whether it is armstrong number or not //eg: if the entered number has 3 digits, raise power 3 to each digits and add them //if it has 4 digits, then raise power 4 to all and sum them printf("Before: count: %d, Sum: %d\n\n", count, sum); for(num; num != 0; num = num / 10){ d = num % 10; for (i = 0; i < count; ++i){ sum = sum * d; printf("Sum in every loop: %d\n", sum); sum2 += sum; //sum = sum + (d * d * d); } } printf("%d \t %d\t%d\n", sum, tnum, sum2); if(tnum == sum) printf("%d is armstrong number", tnum); else printf("%d is not armstrong number", tnum); return 0; } It is not returning expected results.
#include <stdio.h> int main() { //num: to store number entered by the user int num; //count: to count number of digits int count = 0; //i: for looping int i; //for calculating sum int sum = 0, sum2 = 0; //for storing individual digits int d = 1; //tcount, tnum: temporary containers for num and count's original values as it is goimg to be modified in our program int tcount, tnum; //Ask the user to input the number printf("Enter a number: "); scanf("%d", &num); //store the original value of 'num' in temporary varible i.e 'tnum' tnum = num; //Checking the number of digits in the user input for(i = 0; num != 0; i++) { num = num / 10; count = count + 1; } //reassign the original value of num to tnum as it was modified in the above loop num = tnum; tcount = count; //get the number of digits in the input, now raising the power total number to each digits to check whether it is armstrong number or not //eg: if the entered number has 3 digits, raise power 3 to each digits and add them //if it has 4 digits, then raise power 4 to all and sum them /* printf("Before: count: %d, Sum: %d\n\n", count, sum); for(num; num != 0; num = num / 10){ d = num % 10; for (i = 0; i < count; ++i){ sum = sum * d; printf("Sum in every loop: %d\n", sum); sum2 += sum; //sum = sum + (d * d * d); } } */ for(; num != 0; num /= 10){ // getting digits from the given number int d = num % 10; // now we need to set the power of d with count (d^count) int res = 1; for(int ii=0; ii<count; ++ii){ res *= d; } if(d != 0) sum += res; } printf("%d \t %d\t%d\n", sum, tnum, sum2); if(tnum == sum) printf("%d is armstrong number", tnum); else printf("%d is not armstrong number", tnum); return 0; }
01000001011011010100000101101110
i would use pow
I would suggest binary exp.
Anonymous
#include <stdio.h> int main() { //num: to store number entered by the user int num; //count: to count number of digits int count = 0; //i: for looping int i; //for calculating sum int sum = 0, sum2 = 0; //for storing individual digits int d = 1; //tcount, tnum: temporary containers for num and count's original values as it is goimg to be modified in our program int tcount, tnum; //Ask the user to input the number printf("Enter a number: "); scanf("%d", &num); //store the original value of 'num' in temporary varible i.e 'tnum' tnum = num; //Checking the number of digits in the user input for(i = 0; num != 0; i++) { num = num / 10; count = count + 1; } //reassign the original value of num to tnum as it was modified in the above loop num = tnum; tcount = count; //get the number of digits in the input, now raising the power total number to each digits to check whether it is armstrong number or not //eg: if the entered number has 3 digits, raise power 3 to each digits and add them //if it has 4 digits, then raise power 4 to all and sum them /* printf("Before: count: %d, Sum: %d\n\n", count, sum); for(num; num != 0; num = num / 10){ d = num % 10; for (i = 0; i < count; ++i){ sum = sum * d; printf("Sum in every loop: %d\n", sum); sum2 += sum; //sum = sum + (d * d * d); } } */ for(; num != 0; num /= 10){ // getting digits from the given number int d = num % 10; // now we need to set the power of d with count (d^count) int res = 1; for(int ii=0; ii<count; ++ii){ res *= d; } if(d != 0) sum += res; } printf("%d \t %d\t%d\n", sum, tnum, sum2); if(tnum == sum) printf("%d is armstrong number", tnum); else printf("%d is not armstrong number", tnum); return 0; }
Thank you☺️☺️☺️😍
01000001011011010100000101101110
correctmaninwrongplace
I would suggest binary exp.
are there an implemented method ? i dont know, if he is learning, is the simplest solution
01000001011011010100000101101110
are there an implemented method ? i dont know, if he is learning, is the simplest solution
I don't think it has implemented solution. Yeah, you are right pow seems better.
correctmaninwrongplace
well, he asked or a solution, i gave him ideas
correctmaninwrongplace
no one tries to do ackermann for large number, but the method is there
Wisenky
Thanks for memory leak sir . But still I can not use functions between line 15-16 in vcar.c into void push( )
Anonymous
Ohh 😯 And most Armstrong number values are in the 3 digit numbers, so, only 3 digit values are considered most.
Anonymous
Hello guy's I have question Suppose we have an unsorted array And we want to sort it by swapping(swap by index values) But the swapping indexes should be random Example:- arr={9,8,3,2} i=some random value(less than 4) j=some random value(less than 4) if(arr[i]>arr[j]) temp=arr[i] arr[i]=arr[j] arr[j]=temp Swap until the array is sorted
Ammar
Anyway, why would you do that? Could you show the specific case you are working on?
Anonymous
Screen sharing is allowed here I guess
Ammar
Of course screenshot to the related problem is ok.
dj
loop
Matin Rzaev
Hello guys How I can clear char* inside?For example if I want to clear string's inside I write: string s="";
V01D
I dont think you can do that in C
Anonymous
Hello guys How I can clear char* inside?For example if I want to clear string's inside I write: string s="";
Step 1) If it's a dynamically allocated char array free/delete it Step 2) assign "" to the pointer
Matin Rzaev
int main() { string str = "find longests number"; string temp_str = ""; string longest = ""; for (int i = 0; i < str.length(); i++) { if (str[i] != ' ') temp_str += str[i]; else temp_str = ""; if (longest.length()<temp_str.length()) { longest = temp_str; } } cout << longest << endl; system("pause"); return 0; }
Ammar
Hello guys How I can clear char* inside?For example if I want to clear string's inside I write: string s="";
std::string works in different way with char *. In C, string is null terminated. This means: char x[] = "Hello World"; printf("%s", x); // shows "Hello World" *x = '\0'; printf("%s", x); // shows nothing, strlen(x) is also zero.
V01D
Actually change it to a while loop to make it more efficient
V01D
while (str[i]...
Matin Rzaev
It works thanks guys 👍👍
Rohan
Is it possible to invoke member function for non-class type?
Rohan
anyone help???
Anonymous
where is defined _method_?
Rohan
In javaScript or Python methods can directly invoke for primitive data types..
Talula
anyone help???
We don't even know your code if you have defined _Method_ or not... how can we help?
Anonymous
I have a question, please
Rohan
here we go
Anonymous
is legal to do something like this below? template<T>f(...) { auto var = std::is_same<T, mytype>::type? f_that_return_mytype():f_that_return_another_mytype(); } and if yes, which is the correct way?
Anonymous
here we go
_method_?
Dima
here we go
What the heck
Dima
Lol
Talula
here we go
What the heck is this?
Rohan
_method_ was an argument.. I replaced it with order and i fixed it
Ammar
Is it possible to invoke member function for non-class type?
I think your screenshot does not represent your question. You should give the corresponding screenshot.
Anonymous
I think is not defined, as compiler said...
Dima
Dima
Forget everything you know about python and never touch it again