write a program to gat the digt sum of a number (et. 15=
>1+5=6)

Answer Posted / santhosh kumar

#include<stdio.h>
#include<string.h>

int main ()
{
char no[100];
char num[2];
int i;
int length = 0;
int sum = 0;

memset(num, 0, 2);
printf("Enter the number: ");
gets(no);
length = strlen(no);

for(i=0; i<length; i++)
{
num[0] = no[i];
sum += atoi(num);
}

printf("Sum = %d", sum);
return 0;
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you restore a redirected standard stream?

700


What is break statement?

728


Why can’t we compare structures?

917


What is a pointer value and address in c?

728


How can you return multiple values from a function?

726






What are c preprocessors?

782


What is c standard library?

784


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

2065


What are the disadvantages of a shell structure?

795


Write the syntax and purpose of a switch statement in C.

732


What is d scanf?

678


Explain the difference between strcpy() and memcpy() function?

679


What is the difference between break and continue?

702


What are static variables in c?

728


what is ur strangth & weekness

1935