I want to know how to write a program to obtain sum of the first and last digit of a number?
smithag261
0
Newbie Poster
Recommended Answers
Jump to PostSure... ;)
VB Code:
Function sumFirstLast(number As Integer) As Integer Dim numberString As String numberString = Abs(number) & "" sumFirstLast = Val(Mid(numberString, 1, 1)) + Val(Mid(numberString, Len(numberString), 1)) End Function
Jump to Postor, in C++,
int sumFirstLast( int n ) { char s[32]; return ((n % 10) + (*itoa(n,s,10) - '0')); // itoa converts an int into a string }
All 7 Replies
Toba
99
Junior Poster
Chainsaw
12
Posting Pro in Training
keshalidani
-3
Newbie Poster
WaltP
commented:
bad code, not CODE tags, mix of C and C++. Attempting to help the OP cheat. Terrible post!
-3
keshalidani
-3
Newbie Poster
hiddepolen
32
Posting Whiz in Training
Taywin
312
Posting Virtuoso
arkoenig
340
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.