[ create a new paste ] login | about

Link: http://codepad.org/jrUx18Gc    [ raw code | output | fork ]

C++, pasted on Dec 25:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char* argv[])
{
	static char str[256] = "hel4lo wo435435436rld!!!\0";

	int sum = 0;
	for (int i = 0; str[i] != '\0'; i++)
		if (isdigit(str[i])) sum+=str[i] - '0';

	printf("string = %s\nsum = %d\n",str,sum);

	return 0;
}


Output:
1
2
string = hel4lo wo435435436rld!!!
sum = 41


Create a new paste based on this one


Comments: