Subscribe

RSS Feed (xml)

Tuesday, January 6, 2009

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

#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int main(void)
{
int no, rem, sum=0;
clrscr();
printf("Enter the required number:");
scanf("%d",&no);
while(no>0)
{
rem=no%10;
sum=sum+rem;
no=no/10;
}
printf("\nSum of individual digits of a positive integer is: %d",sum);
getch();
return 0;
}

Note:- here 'rem' means remainder

1 comment:

  1. write a program for the following programme
    *
    * *
    * * *
    * * * *
    * * *
    * *
    *

    ReplyDelete