Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- char * to_String(int n) {
- char temp[11] = { 0 };
- char res[11] = { 0 };
- int j = 0;
- while (n > 0) {
- temp[j] = n % 10 + '0';
- n /= 10;
- j++;
- }
- for (int i = 10; i > 0; i--) {
- res[i] = temp[10 - i];
- }
- return res;
- }
- char * to_string(int n) {
- int m = n;
- char s[11];
- char ss[11];
- int i=0,j=0;
- if (n < 0)// Handling negative numbers
- {
- m = 0 - m;
- j = 1;
- ss[0] = '-';
- }
- while (m>0)
- {
- s[i++] = m % 10 + '0';
- m /= 10;
- }
- s[i] = '\0';
- i = i - 1;
- while (i >= 0)
- {
- ss[j++] = s[i--];
- }
- ss[j] = '\0';
- return ss;
- }
- int ppn(char *op, char *e, char *w) {
- if ((e[0] >= '0' && e[0] <= '9') && (w[0] >= '0' && w[0] <= '9')) {
- if (op == '/') {
- return atoi(e) / atoi(w);
- }
- else {
- return atoi(e) * atoi(w);
- }
- }
- if ((e[0] >= '0' && e[0] <= '9') && (w[0] == '/' || w[0] == '*')) {
- char t1[11], t2[11];
- scanf(" %s %s", &t1, &t2);
- if (op == '/') {
- return atoi(e) / ppn(w[0], t1, t2);
- }
- else {
- return atoi(e) * ppn(w[0], t1, t2);
- }
- }
- if ((e[0] == '/' || e[0] == '*') && (w[0] >= '0' && w[0] <= '9')) {
- char t1[11], t2[11];
- scanf(" %s %s", &t1, &t2);
- //fgets(t1, 11, stdin);
- return ppn(op, ppn(e[0], w, t1), t2); // op:/ e:/ w:100 2 2
- }
- if ((e[0] == '/' || e[0] == '*') && (w[0] == '/' && w[0] == '*')) {
- char t1[11], t2[11], t3[11], t4[11];
- scanf(" %s %s %s %s", &t1, &t2, &t3, &t4);
- //char ppn1[11] = itoa(ppn(w[0], t1, t2));
- //char ppn2[11] = itoa(ppn(e[0], ppn1, t3));
- return ppn(op, ppn(e[0], ppn(w[0], t1, t2), t3), t4);
- }
- }
- int main(void)
- {
- char a, b[11], c[11];
- //scanf("%c %s %s", &a, b, c);
- //printf("%c %s %s", a, b, c);
- int n = 123;
- char * s = to_string(n);
- printf("%s", s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement