Write a C program to find the sum of individual digits of a positive integer. - Code

Latest

programs

Thursday, October 6, 2011

Write a C program to find the sum of individual digits of a positive integer.


/* Write a C program to find the sum of individual digits of a positive integer.*/


#include<stdio.h>
#include<conio.h>


void main()
{
  int num, k=1, sum=0;
  clrscr();
  printf("Enter the number whose digits are to be added:");
  scanf("%d",&num);
while(num!=0)
{
  k=num%10;
  sum=sum+k;
  k=num/10;
  num=k;
}
printf("Sum of the digits:%d",sum);
getch();
}

1 comment:

  1. Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING
    Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

    ReplyDelete