❓ Help Unlock Bartleby

Status
Not open for further replies.
Step 1
According to the provided information:
We need to create a C program that will print all prime numbers from 1 to N

Step 2
The required program is written below:
#include<stdio.h>
#include<math.h>
int PrimeNumber(int i,int n)
{
if(n==i)
return 0;
else
if(n%i==0)
return 1;
else{
return PrimeNumber(i+1,n);
}
}
int main()
{
int n,i;
printf("Enter a positive number: ");
scanf("%d",&n);
printf("Prime Number Between 1 to %d are: ",n);
for(i=2;i<=n;i++)
if(PrimeNumber(2,i)==0){
printf("%d ",i);
}
}

#Output
Computer Science homework question answer, step 2, image 1


The snapshot is below:
Computer Science homework question answer, step 2, image 2


Pa mark as solution nalng po prdsdef
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 324
    Views
  • 2
    Participants
Last reply from:
AZ_2018

Trending Topics

Online now

Members online
1,007
Guests online
1,176
Total visitors
2,183

Forum statistics

Threads
2,276,159
Posts
28,967,949
Members
1,231,144
Latest member
jonreipogi
Back
Top