correct this program anyone please....

This is a discussion on correct this program anyone please.... within the C Programming forums, part of the General Programming Boards category; Qus: write a program using C , Getting 50 numbers from user, and display which are prime and which are ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    3

    correct this program anyone please....

    Qus: write a program using C, Getting 50 numbers from user, and display which are prime and which are not prime separately?

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int n[10],prime[10],nprime[10],j=0,k=0,i,a,count=0;
    clrscr();
    printf("Enter the 5 numbers:\n");
    for(i=0;i<5;i++)
    scanf("%d",&n[i]);
    
    for(i=0;i<5;i++)
    {
    
    for(a=1;a<=n[i];a++)
    {
    if(n[i]%a==0)
    {
    count++;
    }
    }
    
    if(count==2)
    {
    prime[j]=n[i];
    j++;
    }
    else
    {
    nprime[k]=n[0];
    k++;
    }
    }
    printf("\n The prime is :...");
    for(i=0;i<10;i++)
    printf("%3d",prime[i]);
    printf("\n The not prime is :...");
    for(i=0;i<10;i++)
    printf("%3d",nprime[i]);
    getch();
    }

    please correct this program...

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    Take a look here. It is similar.

    And also, there is a preview option before you post. Your code lacks indentation.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    Never ask us to do your work for you. Instead ask us to help you to do your work.

    You first need to learn to indent the code properly, and then you need to tell us what problem you are having with it and ask smart questions about what the exact problem is and precisely how we can help.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,552
    I suggest reading and understanding the full C Tutorial

    C Tutorial - Learn C - Cprogramming.com

    You need at least the first 4 lessons of "Introduction and Basic C Features"
    Please pay extra attention to the "Functions and Program Organization" lesson.
    Functions in C - Cprogramming.com

    I would also think "Structures" and "Arrays" lessons would help you solve this problem.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MD5 program not giving correct hashes.
    By Syscal in forum C Programming
    Replies: 4
    Last Post: 04-30-2012, 04:11 AM
  2. another little program: is this correct?
    By fsx in forum C Programming
    Replies: 7
    Last Post: 05-19-2009, 07:50 AM
  3. is this simple program correct? K&R 1-12
    By fsx in forum C Programming
    Replies: 14
    Last Post: 04-22-2009, 03:04 PM
  4. Is this program correct ?
    By broli86 in forum C Programming
    Replies: 9
    Last Post: 08-02-2008, 06:01 PM
  5. My program works but the numbers are not correct.
    By romeoz in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2003, 10:02 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21