I want to write a program to calculate the sum of the first and last digit of a number.
For example N = 12345 then sum = 6. constraint on number is : 1 <= N <= 1000000.
#include <iostream>
using namespace std;
int main()
{
int T,N;
cin >> T;
for(int i = 0; i < T; i++){
cin >> N;
int digit = N % 10;
while ((N / 10) != 0){
N = N/10;
}
cout << digit + N;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire