NextIndex

Programs in C language

1. Program to find the sum of individual digits of a positive integer.
#include<stdio.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();
}
Input :

7458
Output :

Sum of the digits:24



Father of C Language
Dennis Ritchie

Dennis Ritchie

Born: September 9, 1941, Bronxville
Died: October 9, 2011, Murray Hill