Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <string.h>
- int xuLy(char s[]);
- void xuat(int kq);
- int main()
- {
- char s[100];
- printf("Hay nhap chuoi !\n");
- gets(s);
- int kq = xuLy(s);
- xuat(kq);
- return 0;
- }
- int xuLy(char s[])
- {
- int tong = 0;
- int i = 0;
- while (i < strlen(s))
- {
- int tongSo = 0;
- if (s[i] == '-')
- {
- i++;
- while (s[i] >= '0' && s[i] <= '9')
- {
- tongSo = tongSo * 10 + s[i] - '0';
- i++;
- }
- tongSo = -tongSo;// khi so la so am
- tong = tong + tongSo;
- i++;
- }
- else
- {
- while (s[i] >= '0' && s[i] <= '9')
- {
- tongSo = tongSo * 10 + s[i] - '0';
- i++;
- }
- tong = tong + tongSo;
- i++;
- }
- }
- return tong;
- }
- void xuat(int kq)
- {
- printf("%d\n", kq);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement