Friday, October 21, 2011

Solution to Challenge # 2

So the time for challenge # 2 is over and here is the solution:

Problem Statement: A program that inputs an integer and displays the second last digit present in it.


Sample Input:
1) 341534
2) 95402367
3) 59

Sample Output:

1) 3
2) 6
3) 5





Solution:


#include <iostream>
using namespace::std;
int main(void)
{
        int num;
        int last_digit;
        cout << "Enter an integer: ";
        cin>>num;
        last_digit = num/10%10;
        cout << "Last digit of the entered integer is: "<<last_digit<<endl;
        return 0;
}



This solution is submitted by Tom and is absolutely correct. Congrats Tom! :) I hope you are having fun with C++ and I look forward to your future participation as well.



Wednesday, October 12, 2011

Solution to Challenge # 1

Problem Statement: A program that inputs an integer and displays the last digit present in it.


Sample Input:
1) 341534
2) 95402367
3) 59
Sample Output:
1) 4
2) 7
3) 9

 

Solution:

#include<iostream>

using namespace::std;

int main(void)

{

int num;

int last_digit;

cout<<”Enter an integer: ”;

cin>>num;

last_digit = num%10;

cout<<”Last digit of the entered integer is: ”<<last_digit<<endl;

return 0;

}

It was as simple as that. Best of luck for the next challenge. Smile