PROGRAM TO SUM OF FIVE DIGIT NUMBER

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 SUM OF FIVE DIGIT NUMBER

Postby rohit.wadhwa » Wed Mar 18, 2009 3:42 pm

Code: Select all
   
/* PROGRAM TO SUM OF FIVE DIGIT NUMBER */
    #include<stdio.h>
    #include<conio.h>
    void  main()
    {
    int n;
    int temp;
    int sum=0;
    printf("Enter the 5 digit number\n");
    scanf("%d",&n);

    temp=n%10;
    sum+=temp; /* i.e, sum=sum+temp */
    n/=10;     /* i.e, n=n/10 */


    temp=n%10;
    sum+=temp; /* i.e, sum=sum+temp */
    n/=10;     /* i.e, n=n/10 */
   

    temp=n%10;
    sum+=temp; /* i.e, sum=sum+temp */
    n/=10;     /* i.e, n=n/10 */
   
   
    temp=n%10;
    sum+=temp; /* i.e, sum=sum+temp */
    n/=10;     /* i.e, n=n/10 */
   

    temp=n%10;
    sum+=temp; /* i.e, sum=sum+temp */
    n/=10;     /* i.e, n=n/10 */
   
    printf("The Sum of digts are: %d\n",sum);
 
    getch();
    }
Thanks
Rohit Wadhwa
Site : Study Site
User avatar
rohit.wadhwa
Moderator
 
Posts: 55
Joined: Mon Mar 16, 2009 4:00 pm
Location: Hisar(Haryana)
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