- 1

Q - make a function which checks if the number is prime or not and should return value in true and false. Is the coding alright?

#include <iostream> using namespace std; bool prime (int num); { int i,num; cout<<"Enter the number:"; cin >> num; for (i=2: i<=num i++) { if (num%2==0) return bool prime = false } else { return bool prime = true } int main () { int n; prime (int n); return 0;

5th Dec 2019, 4:48 PM
Dipanjan Basu
Dipanjan Basu - avatar
8 Réponses
+ 1
Does it run?
5th Dec 2019, 4:50 PM
Avinesh
Avinesh - avatar
+ 1
Dipanjan Basu you have a lot of errors, please do not get me wrong but kindly study functions more. Hope this helps. Edit: 0 means false and 1 means true in the output. https://code.sololearn.com/cf1LF2U7Te6f/?ref=app
5th Dec 2019, 5:03 PM
Avinesh
Avinesh - avatar
+ 1
Avinesh no no absolutely not bro. It's just that I am not comfortable with functions completely. Thank you so much for helping out always! :)
5th Dec 2019, 5:07 PM
Dipanjan Basu
Dipanjan Basu - avatar
0
It shows an error in the second bracket '{' it dint show any error otherwise till this
5th Dec 2019, 4:52 PM
Dipanjan Basu
Dipanjan Basu - avatar
0
Avinesh yes it shows some errors if I remove the brackets could you correct it for me?
5th Dec 2019, 5:00 PM
Dipanjan Basu
Dipanjan Basu - avatar
0
~ swim ~ just started with it 2 months
5th Dec 2019, 5:05 PM
Dipanjan Basu
Dipanjan Basu - avatar