Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

annas

C program to find prime numbers

  • one year ago
  • one year ago

  • This Question is Closed
  1. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    #include<stdio.h> #include<conio.h> void main() { int a,b; // initialization of variables clrscr(); // clear screen printf("Enter a Number:"); // display message scanf("%d",&a); //get value printf("\n\nPrime Factors of %d is: ",a); //display message for(b=2;b<=n;b++) //loop { // starting of for loop if(a%b==0) // if a/b and remainder is 0 then { printf("%d,",b); a=a/b; b--; if(a==1) break; } } getche(); }

    • one year ago
  2. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    @ParthKohli

    • one year ago
  3. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    Even though I don't understand this, I like it :P Great work! I appreciate it :)

    • one year ago
  4. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    \[\Huge \ddot \smile \]

    • one year ago
  5. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    its for finding prime number but in C

    • one year ago
  6. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    Yeah.. I can see that :)

    • one year ago
  7. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    I'm able to read the code a little. If(a%b == 0) means that the modulus of a and b is 0, correct?

    • one year ago
  8. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    More like \(a \text{ mod} b = 0\). == defines checking something.

    • one year ago
  9. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    yes but % = remainder operator

    • one year ago
  10. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    Yes, it's the same thing. :) http://www.cprogramming.com/tutorial/modulus.html

    • one year ago
  11. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    yap

    • one year ago
  12. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    http://pythonism.wordpress.com/2008/05/04/looking-at-prime-numbers-in-python/

    • one year ago
  13. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    python programming

    • one year ago
  14. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    So, wish me luck in Python!

    • one year ago
  15. ParthKohli
    Best Response
    You've already chosen the best response.
    Medals 0

    Annas dada ki\[\Huge\mathsf{\text{Jai Ho!}} \]

    • one year ago
  16. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    lol

    • one year ago
  17. anusha.p
    Best Response
    You've already chosen the best response.
    Medals 1

    @annas is this the program to write the prime numbers or the program to find out the prime factors of a number..???

    • one year ago
  18. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    @anusha.p its for prime factors of a number thanks for figuring that out :)

    • one year ago
  19. anusha.p
    Best Response
    You've already chosen the best response.
    Medals 1

    u didn't declare n annas....aslo..u didn't initialize n...

    • one year ago
  20. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    thank you @anusha.p my typo mistake i m sorry lemme correct it

    • one year ago
  21. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    first of all prime number program: #include<stdio.h> #include<conio.h> void main() { int n, i = 3, count, c; printf("Enter the number of prime numbers required\n"); scanf("%d",&n); if ( n >= 1 ) { printf("First %d prime numbers are :\n",n); printf("2\n"); } for ( count = 2 ; count <= n ; count++ ) { for ( c = 2 ; c <= i - 1 ; c++ ) { if ( i%c == 0 ) break; } if ( c == i ) { printf("%d\n",i); count++; } i++; } return 0; }

    • one year ago
  22. anusha.p
    Best Response
    You've already chosen the best response.
    Medals 1

    also... if(a%b==0) {........... ............. } if(a==1) { .......... ......... } getch(); }

    • one year ago
  23. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    #include<stdio.h> #include<conio.h> void main() { int a,b; // initialization of variables clrscr(); // clear screen printf("Enter a Number:"); // display message scanf("%d",&a); //get value printf("\n\nPrime Factors of %d is: ",a); //display message for(b=2;b<=a;b++) //loop { // starting of for loop if(a%b==0) // if a/b and remainder is 0 then { printf("%d,",b); a=a/b; b--; if(a==1) break; } } getche(); } now its ok actually i wrote it in hurry so got some mistakes. and @anusha.p i m very much thankful to you for helping me out :) really appreciated it. @anusha.p brackets are rightly placed :)

    • one year ago
  24. anusha.p
    Best Response
    You've already chosen the best response.
    Medals 1

    no mention.......... yeah..braces are at their respective places only....lol.......sorry..

    • one year ago
  25. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    oh there is one more mistake : #include<stdio.h> #include<conio.h> void main() { int a,b; // initialization of variables clrscr(); // clear screen printf("Enter a Number:"); // display message scanf("%d",&a); //get value printf("\n\nPrime Factors of %d is: ",a); //display message if(a==1){ break; } else{ for(b=2;b<=a;b++) //loop { // starting of for loop if(a%b==0) // if a/b and remainder is 0 then { printf("%d,",b); a=a/b; b--; } } } getche(); }

    • one year ago
  26. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    what i did is i put the if condition where the user gives value

    • one year ago
  27. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    thank you once again @anusha.p

    • one year ago
  28. annas
    Best Response
    You've already chosen the best response.
    Medals 5

    getch() and getche() are used to get input from the keyboard in character but in getche() it will display character on screen too. here "e" stands for echo

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.