Skip to main content

Posts

Showing posts from May, 2022

Write a c program to print all prime numbers for 1 to n

 Write a c program to print all prime numbers for 1 to n example problem #include<stdio.h> void main(){    int i, num, n, count;    printf("Enter the range: \n");    scanf("%d", &n);    printf("The prime numbers in between the range 1 to %d:",n);    for(num = 1;num<=n;num++){       count = 0;       for(i=2;i<=num/2;i++){          if(num%i==0){             count++;          break;       }    }    if(count==0 && num!= 1)       printf("%d ",num);    } } Output the prime numbers for 1 to n Enter the range:50 The prime numbers in between the range 1 to 50: 2 3 5 7 11 13 17 19 23 29 31 37 41