-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_03_08_19.c
More file actions
89 lines (69 loc) · 1.42 KB
/
Copy pathTask_03_08_19.c
File metadata and controls
89 lines (69 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Question : Given an array of interger ,
print all alternate prime number from that list
*/
#include<stdio.h>
#include<malloc.h>
/* Select one element of an given array and first check it is a prime
or not, if it is a prime then check the alternatives of
that sequenece of PRIME number
*/
void primeNumber(int arr[], int n)
{
// set the flag which deside alternate of given prime number
int c = 0;
//Select one element of given array
for(int i = 0; i < n; i++)
{
if(arr[i] == 1 || arr[i] == 0)
continue;
// set the flag to check prime or not
int f = 1;
// find out the given number is prime or not
for(int j = 2; j <= (arr[i]/2); j++)
{
if(arr[i] % j == 0)
{
f = 0;
break;
}
}
// check the given number is prime or not
if(f == 1)
{
// alternatives of prime number to dispaly element
if(c == 0)
{
printf("%d\t",arr[i]);
c = 1;
}
else
{
c--;
}
}
}
}
// display function
void display(int arr[], int n)
{
for(int i = 0; i < n; i++)
printf("%d\t",arr[i]);
}
// Entry point function
int main()
{
int *arr,n;
printf("Enter the how many number\n");
scanf("%d",&n);
arr = (int*)malloc(sizeof(int)*n);
printf("Enter the number \n");
for(int i = 0; i < n; i++)
{
scanf("%d",&arr[i]);
}
printf("\n\n");
display(arr,n);
printf("\n\nGiven alternet prime number from that list : \n");
primeNumber(arr,n);
printf("\n\n");
}