Computer Science, asked by Bapibigbos70631, 1 year ago

Write a shell program to display first n prime numbers

Answers

Answered by nikhil062
1
include<stdio.h> int main() { printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); int n,i = 3, count, c; printf("\nEnter the number of prime numbers required : "); scanf("%d", &n); if(n >= 1) { printf("\n\nFirst %d prime numbers are : ", n); printf("2 "); } // iteration for n prime numbers // i is the number to be checked in each iteration starting from 3 for(count = 2; count <= n; i++) { // iteration to check c is prime or not for(c = 2; c < i; c++) { if(i%c == 0) break; } if(c == i) // c is prime { printf("%d ", i); count++; // increment the count of prime numbers } } printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n"); return 0;
Similar questions