C Language
#include<stdio.h> #include<conio.h> void main( ) { int n, r, s = 0, i = 1; clrscr( ); printf("Enter any 4 Digit Number = ") ; scanf("%d",&n); while (n > 0) { r = n % 10; n = n / 10; if (i==1||i=4) { s= s+r; } i++; } printf("Sum of First and Fourth Digit = %d", s); getch( ); } /*OUTPUT*/ Enter any 4 Digit Number = 1286 Sum of First and Fourth Digit = 7