-
Notifications
You must be signed in to change notification settings - Fork 0
/
practiceq2.c
147 lines (138 loc) · 3.01 KB
/
practiceq2.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "cs1010.h"
#include <math.h>
#include <stdbool.h>
long sum(n){
if(n==0){
return 0;
}
return n + sum(n-1);
}
long hcf(long n1, long n2){
if(n2==0){
return n1;
}
return hcf(n2,n1%n2);
}
long lcm(long n1, long n2, long count){
if(count%n1 ==0 && count%n2 ==0){
// cs1010_println_long(count);
return count;
}
count= count+1;
return lcm(n1,n2,count);
}
long cube(long n){
return n*n*n;
}
long cube_of_digits(long n){
if(n<10){
return cube(n);
}
else{
long last_digit = cube(n%10);
long rest =n/10;
return last_digit +cube_of_digits(rest);
}
}
bool armstrong(long n){
if(cube_of_digits(n)==n){
return true;
// cs1010_println_string("It is an armstrong number");
}
else{
return false;
//cs1010_println_string("it is not");
}
}
bool is_prime(long n, long divisor, long end){
if(divisor>end){
return true;
}
if(n%divisor==0){
return false;
}
else{
divisor = divisor+1;
return is_prime(n,divisor,end);
}
}
long recursiv_reverse(long num){
int length = log10(num);
if(num == 0){
return 0;
}
return((num%10*pow(10,length))+recursiv_reverse(num/10));
}
long loop_reverse(long n){
long length_of_number = log10(n);
long m = 0;
long count = length_of_number;
while(n>0){
long temp = n%10;
m = m+ temp*pow(10,count);
n = n/10;
count = count-1;
}
return m;
}
void unique_printer(long* data, long length){
//this is a function that prints unique elements in an array
long temp_arr[length+1];
long i =0;
while(i<length+1){
temp_arr[i] = 0;
i = i+1;
}
long temp = 0;
while(temp<length){
long tempf = data[temp];
temp_arr[tempf] += 1;
temp = temp+1;
}
i = 0;
long count = 0;
while(i<length+1){
long number = temp_arr[i];
if(number ==1){
count +=1;
cs1010_print_long(i);
cs1010_print_string(" ");
}
i = i+1;
}
if(count ==0){
cs1010_println_string("no unique found");
}
cs1010_println_string("");
}
int main(){
int x = 9;
if(2.5<x<7.5){
cs1010_print_string("nnn");
}
else{
x++;
}
cs1010_print_double(x);
return 0;
//long n1 = cs1010_read_long();
//long* n2 = cs1010_read_long_array(n1);
//unique_printer(n2,n1);
//cs1010_println_long(loop_reverse(n1));
/*
if(is_prime(n1,2,sqrt(n1))){
cs1010_println_string("It is prime");
}
else{
cs1010_println_string("not prime");
}
*/
//if(armstrong(n1)){
// cs1010_println_string("It is an armstrong number");
//}
//else{
// cs1010_println_string("It is not an armstrong number");
//}
//long n2 = cs1010_read_long();
//cs1010_println_long(lcm(n1,n2,2));
}