C Program to find the digits of a given number and their sum
write(*,*)'Enter the integer:'
read(*,*)n
m=n
sum=0
if (n.eq.0)then
write(*,*)'The number is',n
write(*,*)'The sum is',sum
else
write(*,*)'The digits are given below :'
do while (n.ne.0)
r=abs(mod(n,10))
write(*,*)r
sum=sum+r
n=n/10
end do
write(*,*)'The sum is',sum
end if
end
write(*,*)'Enter the integer:'
read(*,*)n
m=n
sum=0
if (n.eq.0)then
write(*,*)'The number is',n
write(*,*)'The sum is',sum
else
write(*,*)'The digits are given below :'
do while (n.ne.0)
r=abs(mod(n,10))
write(*,*)r
sum=sum+r
n=n/10
end do
write(*,*)'The sum is',sum
end if
end
Comments
Post a Comment