-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab10q2.cpp
65 lines (61 loc) · 900 Bytes
/
lab10q2.cpp
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
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int num;
double fact;
}numbers_t;
int is_prime(int num, int i)//i is a divisor
{
if (i == 1)
{
return 1;
}
else if (num%i==0)
{
return 0;
}
else
{
is_prime(num, i + 1);
}
}
double fact(int num)
{
if (num == 1)
{
return 1;
}
else
{
return(num * fact(num - 1));
}
}
int main()
{
int m, n;
int i ;
int k=0;
int prime;
numbers_t *odd;
printf("Enter the value of m:");
scanf("%d", &m);
printf("Enter the value of n:");
scanf("%d", &n);
odd = (numbers_t *)malloc((m / 2 + 1) * sizeof(numbers_t));
for ( i = 1; i < m; i++)
{
if (i%2==1)
{
odd[k].num == i;
odd[k].fact = fact(i);
k++;
}
}
printf("ODD NUMBERS\n");
for ( i = 0; i < k; i++)
{
printf(" %d %0.2f\n", odd[i].num, odd[i].fact);
}
system("PAUSE");
return 0;
}