link - here is the link to the question. Can somebody plz help me, I’m stuck. My code is given below.
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
for(int i=0;i<t;i++){
int n;
int ones =0, tens=0, hundreds=0, thousands=0, tenthousands=0, tenlakhs=0, lakhs=0;
cin>>n;
switch (n){
case ( 10 > n):
cout<<n;
break;
case ( 9<n || n<100):
ones = n%10;
tens = n/10;
tens = trunc(tens);
cout<<ones+tens;
break;
case ( 99<n || n<1000):
tens = trunc((n%100)/10);
ones = tens%10;
hundreds = trunc(n/100);
cout<<ones+tens+hundreds;
break;
case ( 999<n || n<10000):
hundreds = trunc((n%1000)/100);
tens = trunc((n%100)/10);
ones = n%10;
thousands = trunc(n/1000);
cout<<ones+tens+hundreds+thousands;
break;
case ( 999<n || n<10000):
hundreds = trunc((n%1000)/100);
tens = trunc((n%100)/10);
ones = n%10;
thousands = trunc((n%10000)/1000);
tenthousands = trunc(n/10000);
cout<<ones+tens+hundreds+thousands+tenthousands;
break;
case ( 999<n || n<10000):
hundreds = trunc((n%1000)/100);
tens = trunc((n%100)/10);
ones = n%10;
thousands = trunc((n%10000)/1000);
tenthousands = trunc((n%100000)/10000);
lakhs = trunc(n/100000);
cout<<ones+tens+hundreds+thousands+tenthousands+lakhs;
break;
case ( 999<n || n<10000):
hundreds = trunc((n%1000)/100);
tens = trunc((n%100)/10);
ones = n%10;
thousands = trunc((n%10000)/1000);
tenthousands = trunc((n%100000)/10000);
lakhs = trunc((n%100000)/10000);
tenlakhs = trunc(n/1000000);
cout<<ones+tens+hundreds+thousands+tenthousands+tenlakhs;
break;
}
}
return 0;
}
It would be very grateful if you help me.