If a four digit number is input through the keyboard, write a program to obtain the sum of first and last of this number.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int num, p, sum = 0;
clrscr ( );
printf ("\n\n\n\t Enter a four digit number...:"); scanf ("%d",&num);
p = num / 1000; /* first digit */
sum = sum + p; /* sum updated with addition of first digit */
p = num % 10; /* last digit */
sum = sum + p; /* sum updated with addition of last digit */
printf ("\n\n\n\t Sum of first and last digit of %d is...:%d",num, sum);
getch ( );
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
void main ( )
{
int num, p, sum = 0;
clrscr ( );
printf ("\n\n\n\t Enter a four digit number...:"); scanf ("%d",&num);
p = num / 1000; /* first digit */
sum = sum + p; /* sum updated with addition of first digit */
p = num % 10; /* last digit */
sum = sum + p; /* sum updated with addition of last digit */
printf ("\n\n\n\t Sum of first and last digit of %d is...:%d",num, sum);
getch ( );
}
Click here to contact us
No comments:
Post a Comment