Pages

Sunday 20 May 2012

program to print sum of given digits by user


80./*Write a program to print sum of given digits by user.*/

#include<stdio.h>
#include<conio.h>
void main()
{
            int n, p=0,s,x=1,ct=0,sum=0;
            clrscr();
            printf("Enter The Number:");
            scanf("%d",&n);
            while(ct<n)
            {
            p=0;
            s=x;
            while(s>0)
            {
            p=(p*10)+(s%10);
            s=s/10;
            }
            if(x==p)
            {
            sum=sum+x;
            ct++;
            }
            x++;
            }
            printf("sum is: %d",sum);
            getch();
}



OUTPUT

            Enter The Number : 6
            Sum is : 21

No comments:

Post a Comment