Hazecraft Client Series: The Event Organizing Company “Hazecraft” focuses on event management in a way that creates a win-win situation for all involved stakeholders. Hazecraft doesn’t look at building one time associations with clients but aim at creating long-lasting collaborations that will span years to come. This goal of the company has helped them to evolve and gain more clients within a notable time.
The number of clients of the company from the start day of their journey till now is recorded sensibly and is seemed to have followed a specific series like 2,3,5,7,11,13,17,19, 23,…, etc
Write a program that takes an integer N as the input and will output the series till the Nth term.
Note:
The given series is prime number series.
Input Format:
The first line of the input is an integer N.
Output Format:
The output is a single line series till Nth term, each separated by a space.
Refer sample input and output for formatting specifications.
Sample Input 1:
5
Sample Output 1:
2 3 5 7 11
Sample Input 2:
10
Sample Output 2:
2 3 5 7 11 13 17 19 23 29
Solution
#include <stdio.h>
int main()
{
int n, i = 3, count, c;
scanf("%d", &n);
if (n >= 1)
{
printf("2 ");
//sarvavhathi
}
for (count = 2; count <= n;)
{
for (c = 2; c <= i - 1; c++)
{
if (i % c == 0)
break;
}
if (c == i)
{
printf("%d ", i);
count++;
//sauravhathi
}
i++;
}
return 0;
}
Happy Learning – If you require any further information, feel free to contact me.