Program to delete duplicates from a link list

First and Last Digit | Codechef solution

Problem (First and Last Digit | Codechef solution):-

If Give an integer N . Write a program to obtain the sum of the first and last digits of this number.

Input of First and Last Digit | Codechef solution

The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N.

Output

For each test case, display the sum of first and last digits of N in a new line.

Constraints

  •  T  1000
  •  N  1000000

Example

Input
3 
1234
124894
242323

Output
5
5
5

Code:-

#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--)
    {
        int n,digit=1,sum=0;
        cin>>n;
        int n1=n;
        int r=n%10;
        n=n/10;
        sum+=r;
        
        while(n!=0)
        {
            r=n%10;
            n=n/10;
            digit+=1;
        }
        int f=pow(10,digit-1);
        r=n1/f;
        sum+=r;
        cout<<sum<<endl;
    }
 
    return 0;
}

Recommended Post:

codechef problems:-

Wipro :-

Infytq :-

Key Points;-

Hackerrank:-

C-tutorial:-

See more:-

Leave a Reply

Your email address will not be published.