# Write a c program to find the number of digits in a string

If you find difficult to understand the for loop, please refer For Loop article here: Here, we are calling the SumofDigits Number method. If we create a function with Void then there is no need to return any value but, if we declared a function with any data type int, float etc then we have return something out from the function. Program to Find Sum of Digits in Java using Recursion This program allows the user to enter any positive integer and then it will divide the given number into individual digits and adding those individual Sum digits by calling the function recursively. Consider the following two strings of 32 lowercase letters and digits. The second one has no obvious simple description using the same character set other than writing down the string itself, which has 32 characters.

More formally, the complexity of a string is the length of the shortest possible description of the string in some fixed universal description language the sensitivity of complexity relative to the choice of description language is discussed below. It can be shown that the Kolmogorov complexity of any string cannot be more than a few bytes larger than the length of the string itself. Strings like the abab example above, whose Kolmogorov complexity is small relative to the string's size, are not considered to be complex.

## Sum of digits in C | Programming Simplified

The Kolmogorov complexity can be defined for any mathematical object, but for simplicity the scope of this article is restricted to strings. We must first specify a description language for strings.

Such a description language can be based on any computer programming language, such as LispPascalor Java virtual machine bytecode. If P is a program which outputs a string x, then P is a description of x. The length of the description is just the length of P as a character string, multiplied by the number of bits in a character e.

For theoretical analysis, this approach is more suited for constructing detailed formal proofs and is generally preferred in the research literature. Any string s has at least one description. For example, the second string above is output by the program: Thus, the length of d s i. The length of the shortest description will depend on the choice of description language; but the effect of changing languages is bounded a result called the invariance theorem.

The standard textbook is authored by Ming Li and Paul Vitanyi in the references. Informal treatment[ edit ] There are some description languages which are optimal, in the following sense: The constant depends only on the languages involved, not on the description of the object, nor the object being described.

Here is an example of an optimal description language. A description will have two parts: The first part describes another description language. The second part is a description of the object in that language.

In more technical terms, the first part of a description is a computer program, with the second part being the input to that computer program which produces the object as output. The invariance theorem follows: Given any description language L, the optimal description language is at least as efficient as L, with some constant overhead.

Any description D in L can be converted into a description in the optimal language by first describing L as a computer program P part 1and then using the original description D as input to that program part 2.

So, there is at most a constant overhead, regardless of the object described. Therefore, the optimal language is universal up to this additive constant. A more formal treatment[ edit ] Theorem: Now, suppose there is a program in the language L1 which acts as an interpreter for L2: The interpreter is characterized by the following property: Running InterpretLanguage on input p returns the result of running p.

Thus, if P is a program in L2 which is a minimal description of s, then InterpretLanguage P returns the string s. The length of this description of s is the sum of The length of the program InterpretLanguage, which we can take to be the constant c.

The length of P which by definition is K2 s. This proves the desired upper bound. History and context[ edit ] Algorithmic information theory is the area of computer science that studies Kolmogorov complexity and other complexity measures on strings or other data structures.

The concept and theory of Kolmogorov Complexity is based on a crucial theorem first discovered by Ray Solomonoffwho published it indescribing it in "A Preliminary Report on a General Theory of Inductive Inference"  as part of his invention of algorithmic probability.

Transmission  in Gregory Chaitin also presents this theorem in J. This algorithm, for all strings, allows codes as short as allowed by any other algorithm up to an additive constant that depends on the algorithms, but not on the strings themselves.

Solomonoff used this algorithm, and the code lengths it allows, to define a "universal probability" of a string on which inductive inference of the subsequent digits of the string can be based. Kolmogorov used this theorem to define several functions of strings, including complexity, randomness, and information.

When Kolmogorov became aware of Solomonoff's work, he acknowledged Solomonoff's priority.Table of Content. C Program to Find Length of String Without using Library Function; C Program to Reverse Letter in Each Word of the Entered String; C Program to Find Length of the String using Pointer; C Program to Count number of words,digits.

A Few FORMAT Recipes. Common Lisp's FORMAT function is--along with the extended LOOP macro--one of the two Common Lisp features that inspires a strong emotional response in a lot of Common Lisp users. Some love it; others hate it. 1 FORMAT's fans love it for its great power and concision, while its detractors hate it because of the potential for misuse and its opacity.

C program to count number of vowels in a string: C programming code to find how many vowels are present in a string. For example, in the string "C programming" there are three vowels 'o', 'a' and 'i'.

C++ programs to Count number of vowels, consonants, Digits, Space in a String - Write a programs in C++ to count number of vowels, consonants, Digits, Space in a String. C++ Program to Find Number of vowels in string. Write a C program to input a number from user and find sum of digits of the number using for loop.

## C programming Interview questions and answers: C program examples | Interview Complete List

Logic to find sum of digits of a number in C programming. Learn C programming, Data Structures tutorials, exercises, . Simple Java Program to check or find if a number is Armstrong number or not. [ An Armstrong number of any number of digit is a number whose sum of each digits raised to the power the total no.

of digits is equal to it (the original number).

Java Count Number of Digits in a given number