img
Question:
Published on: 21 December, 2024

Write a C program to find sum of digit of any no.

Answer:
#include<stdio.h>
#include<conio.h>
main()
{
	int n,digit,sum=0;
	printf("\n enter any number");
	scanf("%d",&n);
	while(n>0)
	{
		digit=n%10;
		sum=sum+digit;
		n=n/10;
	}
	printf("\n the sum=%d",sum);
	getch();
}

Output:



 
Random questions