Friday, November 23, 2012

INPUT TWO INTEGERS 'N' AND 'M'.FIND THE NO. OF PRIME NUMBERS B/W 'N' AND 'M'(CREATE A FUNCTION WHICH FINDS IF THE GIVEN NO. IS PRIME.THIS FUNCTION CAN BE CALLED REPEATEDLY).


/*  INPUT TWO INTEGERS 'N' AND 'M'.FIND THE NO. OF PRIME NUMBERS
    B/W 'N' AND 'M'(CREATE A FUNCTION WHICH FINDS IF THE GIVEN NO. IS
    PRIME.THIS FUNCTION CAN BE CALLED REPEATEDLY).
 */

#include<stdio.h>
#include<conio.h>

main()
{
            int n,m,flag,i,count=0;
            clrscr();
            printf("\n Enter The Value for 'N'      : ");
            scanf("%d",&n);
            printf("\n Enter the Value for 'M'[M>N] : ");
            scanf("%d",&m);
            if((n<m)&&(n>1))
            {
                        printf("\n The Prime No. are...\n");
                        for(i=n;i<=m;i++)
                        {
                                    flag=prime(i);
                                    if(flag==0)
                                    {
                                                printf("%d \n",i);
                                                count++;
                                    }
                        }
                        printf("\n There are \'%d\' PRIME no. B/W %d and %d.",count,n,m);
            }
            else
            printf("\n Invalid Condition... ");
            getch();
}
/* FUNCTION TO FIND PRIME NO. */
prime(int i)
{
            int j,f;
            f=0;
            for(j=2;j<=i/2;j++)
            if(i%j==0)
            f=1;
            return(f);
}

/*
            =====OUT PUT=====

            1. Enter The Value for 'N'      : 9

           Enter the Value for 'M'[M>N] : 2

           Invalid Condition...

            2. Enter The Value for 'N'      : 2

           Enter the Value for 'M'[M>N] : 25

                The Prime No. are...
               2
               3
               5
           7
               11
               13
               17
               19
               23

               There are '9' PRIME no. B/W 2 and 25.

*/

0 comments:

Post a Comment