If a four digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of that number.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int md, no, co = 1, s = 0;
clrscr ( );
printf ("\n\t Enter a four digit number ......:"); scanf ("%d",&no);
while ( no > 0 )
{
md = no % 10;
no = no / 10;
if ( co == 1)
s = s + md;
co ++;
}
s = s + md;
printf ("\n\t SUM = %d",s);
getch ( );
}
No comments:
Post a Comment