Add Digits of the Number Using Single Statement :
#include<stdio.h>
void main()
{
int number=12354;
int sum=0;
for(;number > 0;sum+=number%10,number/=10);
printf("nSum of the Digits : %d",sum);
}Output :
15
How ?
for(initialization ; conditional ; increment)
{
//body
}- In ‘For Loop‘ Condition is first tested and then body is executed.
- Carefully Look at Semicolon at the end of ‘For Loop’ , which tells us two Things -
- For Loop is Bodyless.
- Only Condition and Increment Statements will be executed.
Incoming search terms:
- c program to find the sum of digits of a number without using conditional statements and looping statements (1)
- how to add the digits of a number without loop in java (1)
- how to add100 digits in c program (1)
- java sum of digits in one line (1)
- program of sum of digits of a number in javascript using prompt (1)
- single line program of sum of digits without using semicolon in c (1)

