please help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

please help

I have this problem as homework and I don't know what is my mistake A natural number n is read from the keyboard. Make the program that determines the sum of the elements less than or equal to n that are primes and palindromes. #include <iostream> using namespace std; int main() { int n,ok,d,s,ogl,i,i1; cin>>n; for(i=1;i<=n;i++) ok=1; if(i==0 || i==1) ok=0; else for(d=2;d<=i/2;d++) if(i%d==0) ok=0; if(ok==1) ogl=0; i1=i; while(i1!=0) {ogl=ogl*10+i1%10; i1=i1/10; } if(ogl==i) s=s+i; cout << s; }

24th Nov 2020, 3:36 PM
HAPYX 1
HAPYX 1 - avatar
2 Answers
+ 4
Either the code is badly indented or you are missing a lot of braces {} in your code. Also I can see you have not initilised variable "s" so it will add up so some heavenly👼 value during execution.
24th Nov 2020, 3:51 PM
Arsenic
Arsenic - avatar
+ 1
thanks a lot!! I saw my mistakes now...
24th Nov 2020, 3:59 PM
HAPYX 1
HAPYX 1 - avatar