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

0 response(s):

Respond to this Post

Your participation is appriciated...