PROGRAM TO FIND SUM OF FIVE DIGITS

C, C++, etc Programing examples. Post as many you can. Test the programs and discuss about the output of the programes.
Forum rules
Please Discuss & post only about the programes and its Output

PROGRAM TO FIND SUM OF FIVE DIGITS

Postby charulatha » Tue Apr 13, 2010 2:26 pm

/* PROGRAM TO FIND THE SUM OF 5 DIGITS IN A 5-DIGIT NUMBER*/

#include<stdio.h>
#include<conio.h>
main()
{
long int no;
int a,n;
int sum=0;
printf("Enter 5 digit number\n");
scanf("%ld",&no);

a=no%10;
sum=sum+a; /* sum of one digit*/
n=no/10;

a=n%10;
sum=sum+a;/* sum of two digit */
n=n/10;

a=n%10;
sum=sum+a;/* sum of three digit */
n=n/10;

a=n%10;
sum=sum+a; /* sum of four digits*/
n=n/10;
a=n%10;
sum=sum+a; /* sum of five digits */
printf("sum=%d\n",sum);
getch();
}
Regards,
Charulatha.
User avatar
charulatha
Moderator
 
Posts: 756
Joined: Sat Oct 17, 2009 2:54 pm
membership: Senior Technician of The Institution of Engineers (India)- ST

ad
 

Return to Computer Notes : Some Sample Programs

Who is online

Users browsing this forum: No registered users and 0 guests