❓ 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
  • 346
    Views
  • 2
    Participants
Last reply from:
AZ_2018

Trending Topics

Online now

Members online
1,086
Guests online
2,408
Total visitors
3,494

Forum statistics

Threads
2,316,703
Posts
29,187,753
Members
1,182,043
Latest member
Gbonds
Back
Top