How to add the first and last digit of 0101 in c++? write a program step by step in c++.
Answers
Answer:
hello, if we are talking about 0101 as a binary number where it is equivalent
to 5 in decimal of base 10 then, both the first and last digit of the number are
same so you can simply do this int c = 5 + 0; cout << c;
this will result in 5 as output.
BUT, if we are talking about 0101 as a natural number i.e. one hundred one
then there is a simple trick to add first & last digits of it
simply do this..
#include <iostream>
int main() {
int num = (0101)%10 + (0101) %1000;
cout << num; //outputs 1 as the answer
return 0;
}
OR you can do this as well;
int num = 0101%10; //it will give you the first digit
while(num >0 && num<10) num /= 10; //this will reduce num to single leftmost
// digit
Reference:
for further material on such questions please visit
for modulo operator
https://brainly.in/question/3824772
for arithmetic operations in c++
https://brainly.in/question/1762969