Source Code :
#include<stdio.h>
void main()
{
      int a,sum=0,rem,div,ctr=1;
      clrscr();
      printf("\nEnter a 4-digit Number : ");
      rem=a;
      div=a;
      while(rem!=0)
      {
            rem=rem%10;
            div=div/10;
            if(ctr==1 || ctr==4)
            {
                  sum+=rem;
            }
            rem=div;
            ctr++;
      }
      printf("\nSum of the First and Last Digit : %d",sum);
      getch();
}
Output :
Enter a Number : 1234
 
 
 
No comments:
Post a Comment