DO NOT MISS

Ads

Sunday, 31 July 2016

Program 17 Using While Loop


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

void main()

     {

           int n,sum=0,r;
           clrscr();

           printf("enter a number:");
           scanf("%d",&n);

     
     while(n!=0)
                    {
                          r=n%10;
                          sum=sum+r;
                          n=n/10;
                     }

            printf("the sum of the digits of the given no. is:=%d",sum);

            getch();

       }

Output:-


Explanation:
enter the number:34=3 + 4 =7
enter the number:59=5 + 9=14

______________________________________________________
______________________________________________________
______________________________________________________
_____________________________________________________

Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims