Answer to Question #300224 in C++ for king

Question #300224

Write a program in C language that print the sum of first and last digit of 7 digit


input number N (5)


[For example if N=98765 the output is 9(First Digit) + 5(Last Digit)=14

1
Expert's answer
2022-02-21T11:04:37-0500
#include<stdio.h>






int sum(int number)
{
	int digit1;
	int digit2=number%10;
	number=number/10;
	while(number)
	{
		digit1=number%10;
		number=number/10;
	}
	return digit1+digit2;
}


int main(){
	int number;
	printf("Enter any positve integer number (7 digits): ");
	scanf("%d",&number);
	printf("The sum of first and last digit of 7 digit %d is: %d ",number, sum(number));
	scanf("%d",&number);


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog