-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharithmatic.c
129 lines (95 loc) · 2.4 KB
/
arithmatic.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
#if 0
#include <stdio.h>
int main(void)
{
int arr[] = {2, 3, 4, 5, 6};
printf("Size of arra [%d]", sizeof(arr));
int mod = 2/5;
printf("Mod is [%d]\n", mod);
}
#include <stdio.h>
#include <math.h>
double power(double x, double y)
{
double result=0;
if (y==0)
return 1;
else {
result = x*power(x, y-1);
return result;
}
}
/* power method implementation in C */
int main(){
int number[8] = {1,0,0,0,1,0,1,0}, result = 0, x;
int elements = sizeof(number)/sizeof(int);
int num = elements-1;
x=0;
while(num >=0) {
result += (power(2,x)* number[num]);
num--;
x++;
}
printf("Final result: %d\n", result);
return 0;
}
#endif
#include <stdio.h>
//#include <stdlib.h>
int main()
{
/*
int x = -90;
printf("Absolute value of x is [%d] real value [%d]", abs(x), x);
char dest[10];
char *src = "My name is Anupam";
strncpy(dest, src, 6);
printf("Destination [%s] strlen [%d]", dest, strlen(dest));
int n=0;
while(dest[n]!= '\0') {
printf(" %c %d", dest[n], n);
n++;
}
*/
/*
char test;
char ch;
scanf("%c", &test);
scanf(" %c", &ch);
printf("[%c]\n", test);
printf("[%c]", ch);
*/
/*
int i, ii;
char str1[20], str2[30], ch;
float f;
char input[] = "25 45.6 Thompson f";
sscanf(input, "%d %f %s %c", &i, &f, str1, &ch);
printf("[%d] [%f] [%s][%c]", i, f, str1, ch);
*/
/*
char *str1 = "1236abb";
char str2[] = {'3', '6', '7', '9', 'a', 'b'};
int num, num1;
sscanf(str1, "%d", &num);
printf("[%d]", num);
sscanf(str2, "%d", &num1);
printf("[%d]", num1);
*/
/*
char str[10]; // MUST be big enough to hold all the characters of your number!!
printf("15 in binary is %s\n", itoa(15, str, 2));
printf("15 in octal is %s\n", itoa(15, str, 8));
printf("15 in decimal is %s\n", itoa(15, str, 10));
printf("15 in hex is %s\n", itoa(15, str, 16));
*/
//atoi
int num;
char *str = "1234ab";
printf("[%d]", atoi(str));
char str1[20];
int i; float num1=5456.567;
i = sprintf(str1, "%f", num1);
printf("15 in decimal is %s\n", str1);
printf("sprintf returns: %d and strlen is [%d]\n\n", i, strlen(str1));
}