-
Notifications
You must be signed in to change notification settings - Fork 0
/
stk_primediv.c
71 lines (67 loc) · 1.05 KB
/
stk_primediv.c
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
#include <stdio.h>
#include <stdlib.h>
void push(int stack[100],int *top,int data);
int pop(int stack[100],int *top);
void display(int stack[100],int *top);
int primee(int i);
int main() {
int stack[100],top = -1;
int i = 2, n;
scanf("%d",&n);
while(n > 0){
while(primee(i)){
while(n%i == 0){
push(stack,&top,i);
n = n/i;
}
i++;
}
i++;
}
display(stack,&top);
while(top != -1){
i = pop(stack,&top);
printf("%d",i);
}
printf("\n");
return 0;
}
int primee(int i){
int p,flag = 0;
for(p = 2; p <= i/2; p++){
if(i % p == 0 ){
flag = 1;
return 0;
}
}
return 1;
}
void push(int stack[100],int *top,int data) {
if(*top == 99){
printf("overflow\n");
return ;
}
(*top)++;
stack[*top] = data;
}
int pop( int stack[100],int *top) {
if(*top == -1) {
printf("underflow\n");
return -1;
}
int data ;
data = stack[*top];
(*top)--;
return data;
}
void display(int stack[100],int *top) {
int i;
if(*top == -1) {
printf("no element\n");
return;
}
for(i=*top;i>= 0; i--) {
printf("%d",stack[i]);
}
printf("\n");
}