C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf

try this also #include #include using namespace std; int main() { int a,i,n,j,b,k=0; cout<<"enter the first range :"; cin>>a; cout<<"enter the last range :"; cin>>b; for(i=a;i<=b;i++) { k=0; for(j=1;j<=i;j++) { n=i%j; if(n==0) { k=k+1; if(k==2 && i==j ) { cout<<"i="<<i<<endl; } }

## 3 comments:

change i!=0 with i>1, will work with neg integers too

try this also

#include

#include

using namespace std;

int main()

{

int a,i,n,j,b,k=0;

cout<<"enter the first range :";

cin>>a;

cout<<"enter the last range :";

cin>>b;

for(i=a;i<=b;i++)

{

k=0;

for(j=1;j<=i;j++)

{

n=i%j;

if(n==0)

{

k=k+1;

if(k==2 && i==j )

{

cout<<"i="<<i<<endl;

}

}

}

}

return 0;

getch();

}

why do wetake count as variable

Post a Comment