google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a program to find sum of digits in a given number - 2nd puc computer science

Write a program to find sum of digits in a given number

Write a program to find sum of digits in a given number

#include<stdio.h>

#include<conio.h>

void main()

{

int n,sum=0,digit;

clrscr();

printf("enter the number: ");

scanf("%d",&n);

while(n!=0)

{

digit=n%10;

sum=sum+digit;

n=n/10;

}

printf("Sum of digits=%d",sum);

getch();

}

Output:

enter the number: 456

Sum of digits=15                   

Write a program to find sum of digits in a given number Write a program to find sum of digits in a given number Reviewed by Vision Academy on December 08, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.