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

#include<iostream.h>
#include<conio.h>
#include<string.h>
class sod
{
int a,b,c,i,num,num1,sum,n;
public:
void getdata()
{
cout<<"\tProgram for sum of digits\n\n\n";
cout<<"enter a one, two, three, four or five digit number ";
cin>>num;
}
void sumod()
{
sum=0;
n=0;
num1=num;
while(num1>0)
{
b=num1/10;
num1=b;
n++;
}
for(i=0;i<n;i++)
{
a=num%10;
b=num/10;
num=b;
sum=sum+a;
}
}
void putdata()
{
cout<<"\nSum of the digits of the above number is = "<<sum;
}
};
int main()
{
sod s1;
clrscr();
s1.getdata();
s1.sumod();
s1.putdata();
getch();
return 0;
}

#include<iostream.h>
#include<conio.h>
class sod
{
int a,b,c,i,n,sum;
public:
void getdata()
{
cout<<"enter a four digit number ";
cin>>n;
}
void sumod()
{
sum=0;
for(i=0;i<4;i++)
{
a=n%10;
b=n/10;
n=b;
sum=sum+a;
}
}
void putdata()
{
cout<<"\nSum of the digits of the above number is = "<<sum;
}
};
int main()
{
sod s1;
clrscr();
s1.getdata();
s1.sumod();
s1.putdata();
getch();
return 0;
}

function sumDigits(val) {
if (!isNaN(val)) {
val = parseInt(val, 10) // ensure integer
if (val>9) {
var sum = val%10 // last digit number
while (val>10) { // searching for the first number
val = parseInt(val/10, 10)
}
alert(sum+val) // now what left is the last + first digit
}
else { alert(val) }
}
else { alert(val+" is not a number") }
}

Is C similar to C# (C-sharp); or are they completely different ? I was wondering if I should begin learning C# and the transition to C will be a tad ...

Write a program that displays all numbers divisible by 3 and 4 within a range entered by user. Display five numbers per line. Numbers are separated by exactly two spaces. ...

Hi guys. I am trying to create a program where the user inputs an integer and the program will cout the nth prime number. Unfortunatly when I try to cout ...