Sum of First and Last Digits of a Four-Digit number.
This program is based on the "sum of digits" program discussed previously.
This program also has some usage of the Modulus Operator.
If a four-digit number is input through the keyboard,
write a program to obtain the sum of the first and the last digit of this number.
This program also has some usage of the Modulus Operator.
If a four-digit number is input through the keyboard,
write a program to obtain the sum of the first and the last digit of this number.
/*HINT: If a number is divided using % , then the number to the right side of the decimal point
is the result. (This applies only to integers.) */
#include<stdio.h>
main ()
{
int number, last_digit, first_digit, total;
printf (" Enter the number which is to be operated on: ");
scanf ("%d", &number);
last_digit = number % 10;
total = last_digit;
first_digit = (number / 1000) % 10;
total = total + first_digit;
printf ("The total of the first and the last digit of the entered number is: %d", total);
}
/*This program is based on the "Sum of Digits" Program */
The File can be found out at:
Download File
Comments
mayankmehra95@gmail.com
12:25 AM, A
hey how should i do for a four digit number sum?
imgn i need the sum of 4 digits of my car number 2569..
any four digit num which the end user typs i want the sum in single digit..lyk 2+5+6+9=22=>2+2=4
i want result as 4..how?
----------------------
int main()
{
int num,len,last;
printf("\nEnter n digit number \n");
scanf("%d",&num);
last=num%10;
while(num>0)
{
num=num/10;
len=len+1;
}
num=num/(pow(10,len-1));
num=num%10;
printf("the result is %d",last+num);
getch();
return 0;
}
guys check dis out, It will work*/
void main()
{
int num,sum=0,rem;
printf("Enter a number");
scanf(" %d",&num);
rem=num%10;
sum=sum+rem;
while(n>10)
{
num=num/10;
}
rem=num%10;
sum=sum+rem;
printf("sum of 2 digits is: %d",sum);
getch();
}
can you help me with my problem:
a cashier has a currency notes of denominations 10 50 and 100. if the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer
thank you so much!!!
you can reach me through this email
princeryoma17@yahoo.com