Write a program to generate the first n terms in the series --- 2,3,5,7,11,...,17
Input Format:
Input consists of a single integer which corresponds to n.
Output Format:
Output consists of the terms in the series separated by a blank space.
Sample Input:
8
Sample Output:
2 3 5 7 11 13 17 19
Code:
#include<stdio.h> #include<math.h> int main(){ int n,div,count,num,t; scanf("%d",&n); printf("%d ",2); count=1; num=3; while(count<n) { t=sqrt(num); div=2; while(div<=t) { if(num%div==0) break; div++; } if(div>t) { printf("%d ",num); count++; } num=num+2; } return 0; }
ty
ReplyDeleteHello sir, Thank you. But can you please explain the reason for calculating the square root and its comparison.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletewont work shitty code
ReplyDeletecan u please explain this code
ReplyDelete