Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

design c program using functions. (a).generate prime numbers of given range. (b).prime number or not.

0 votes
asked Nov 4, 2018 by anonymous

3 Answers

0 votes
answered Nov 5, 2018 by anonymous
#include <stdio.h>
void fun(int , int);
int main(int argc, char *argv[])
{ int i , n1 , n2 , res;
if(argc != 3)
{printf("please pass atleast two arguments");
    return 0;
}
     n1 = atoi(argv[1]);
     n1 = n1+1;
     n2 = atoi(argv[2]);
     fun(n1 , n2);
    return 0;
}
void fun(int n1, int n2)
{int i , j, count;
        for(i=n1;i<n2;i++)
        {
            count = 0;
            for(j=2;j<n1/2;j++)
            {if(i%j == 0)
                {count ++;}
            }
        if(count == 0)
        {printf("%d\t",i);}
        }    
}
0 votes
answered Nov 5, 2018 by kumar gulshan
find is a number is prime or not-----------------------

#include <stdio.h>
int fun(int);
int main(int argc, char *argv[])
{ int i , n1 , res;
if(argc != 2)
{printf("please pass atleast one argument");
    return 0;
}
     n1 = atoi(argv[1]);
     res = fun(n1);
     if(res == 0)
     printf("%d is a prime number",n1);
     else
     printf("%d is not a prime number",n1);
    return 0;
}

int fun(int n1)
{int j, count, res=0;
        for(j=2;j<n1;j++)
            {if(n1%j == 0)
                {   return 1;}
            }
        return 0;
        }
0 votes
answered Nov 12, 2018 by anonymous
#include <stdio.h>
void isPrime(int);
void isPrimeOrNot(int);
int main()
{
    int n,p;
    printf("Prime number upto number");
    scanf("%d",&n);
    isPrime(n);
    printf("\nenter a number");
    scanf("%d",&p);
    isPrimeOrNot(p);
    return 0;
}
void isPrime(int n)
{
    int i,fact,j;
    printf("Prime Numbers are: \n");
    for(i=1; i<=n; i++)
    {
        fact=0;
        for(j=1; j<=n; j++)
        {
            if(i%j==0)
                fact++;
        }
        if(fact==2)
            printf("%d " ,i);
    }
  }
void isPrimeOrNot(int y)
{
    int i,flag=0;
    for(i=2;i<=y/2;i++)
    {
        if(y%2==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    printf("number is not prime");
    else
    printf("number is prime %d",y);
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...