   # C program to calculate sum of first and last digit values is equal to product of remaining two digits?

1,975 views

Input: 1223
1+3=2*2
that means if sum of 1st and last digit is equal to product of remaining 2 digits then print 1+3=2*2 else error msg. posted Nov 21, 2014

+1 vote

Here is my program(Tested).

``````#include <stdio.h>

int main()
{
int num = 0;
int n, i = 3;

printf("Enter a 4 digit number : ");
scanf("%d", &num);

//I am asumming that, you have enterd a 4 digit number.
while(i >= 0 ) {
n[i--] = num % 10;
num /= 10;
}

if ((n + n) == (n * n)) {
printf("%d + %d = %d * %d\n", n, n, n, n);
} else {
printf("Error : (Sum of 1st and last is not equal to porduct of remaing  two).\n");
}

return 0;
}
`````` answer Nov 24, 2014
Arshad bhai without taking array variable can't we solve this problem i f we can solve the problem pls mail me the program
Yes  absolutely, we can solve the problem without using array.
I am posting that as a second ans.

Second ans without using array.

``````#include <stdio.h>

int main()
{
int num = 0;
int sumof_first_last, prodof_rem2;

printf("Enter a 4 digit number : ");
scanf("%d", &num);

//I am asumming you have enterd a 4 digit number.

sumof_first_last = (num / 1000) + (num % 10);  // it will give first and last digit
prodof_rem2 = ((num / 100) % 10) * ((num / 10) % 10); // it will give 2nd and 3rd digit i.e remaning two.

if (sumof_first_last == prodof_rem2) {
printf("Sum of 1st and last is not equal to porduct of remaing  two i.e = %d\n", sumof_first_last);
}
else {
printf("Error : (Sum of 1st and last is not equal to porduct of remaing  two.\n");
}
return 0;
}
`````` answer Dec 31, 2014
Similar Questions

Rohit wants to add the last digits of two given numbers.
For example, If the given numbers are 267 and 154, the output should be 11.

Below is the explanation -
Last digit of the 267 is 7
Last digit of the 154 is 4
Sum of 7 and 4 = 11

### Write a program to help Rohit achieve this for any given two numbers.

Note: The sign of the input numbers should be ignored. i.e.
if the input numbers are 267 and 154, the sum of last two digits should be 11
if the input numbers are 267 and -154, the sum of last two digits should be 11
if the input numbers are -267 and 154, the sum of last two digits should be 11
if the input numbers are -267 and -154, the sum of last two digits should be 11

import java.io.*
import java.util.*;
class UserMainCode
{
public static long output1;
public static void lastTwoDigitSum(int input1)
{}
}
in this format
plzz someone solve my problem