Thread: what is the problem in this program?

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    22

    what is the problem in this program?

    Code:
    1. #include <stdio.h>
    2. int main()
    3. {
    4. int arr[10];
    5. int i;
    6. for (i=0;i<10;i++) {
    7. scanf("%d",&arr[i]);
    8. }
    9. for (i=0;i<10;i++) {
    10. int flag = 1;
    11. if (arr[i] == 1) flag = 0;
    12. for (int j=2;j<=arr[i]/j;j++) {
    13. if (arr[i]%j == 0) {
    14. flag = 0;
    15. break;
    16. }
    17. }
    18. if (flag) printf("%d ",arr[i]);
    19. }
    20. return 0;
    21. }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well,
    - You included line numbers where the board will do this for you.
    - The code isn't indented.
    - You don't actually say what you want it to do, as opposed to what it does do.
    - You don't provide an example input which apparently "breaks" the code in some undesirable way.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Program Problem Need HELP!!!
    By DMJJR1988 in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2010, 11:18 PM
  2. problem with a c++ program
    By bianca21 in forum C++ Programming
    Replies: 1
    Last Post: 03-29-2009, 12:15 PM
  3. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  4. Problem with an if-else program... ?
    By Beachblue in forum C Programming
    Replies: 4
    Last Post: 05-24-2008, 09:32 AM
  5. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM

Tags for this Thread