25 December 2011

C Program to Find Sum of digits of a Number Excluding First and Last Digits

Leave a Comment

 Program to Find Sum of a Number Excluding First and Last Digits






#include<stdio.h>

void main()
{
int n,num,x,sum=0,count=0,a,last,first,multiple=1;
printf("Enter a number: ");
scanf("%d",&n);
a=n;
//finding the sum of the digits
while(n>0)
{
x=n%10;
sum=sum+x;
n=n/10;
count++;
}
printf("Sum of digits of a number=%d \n the number of digits is %d",sum,count);
last = a%10;
printf("\nthe last digit is %d ",last );
//loop to find first digit of the number
for(;count-1;)
{
multiple *=10;
count--;
}
printf("\nthe first digit is %d ",first=a/multiple);
//subtracting first and last digit from number
printf("\nthe sum of digits excluding first and last digit is %d " ,sum-first-last);
}

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

0 comments:

Post a Comment