Computer Science, asked by HridyaJagtap11, 10 months ago

Write a program to enter a number and display the sum of its digits. (using while loop)
Input : 642 Output : 12 (6+4+2 = 12)

Answers

Answered by vaishnavik052
2

Answer:

#include<stdio.h>

#include<conio.h>

void main()

{

int sum=0,n,i;

printf("enter the numbers");

scanf("%d",&n);

while(n>0)

{

rem=n%10;

sum=sum+rem;

n=n/10;

}

printf("%d sum of digits is",sum);

getch();

}

Explanation:

Similar questions