top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+2 votes
2,635 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 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Here is my program(Tested).

#include <stdio.h>

int main()
{
    int num = 0;
    int n[4], 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[0] + n[3]) == (n[1] * n[2])) {
        printf("%d + %d = %d * %d\n", n[0], n[3], n[1], n[2]);
    } else {
        printf("Error : (Sum of 1st and last is not equal to porduct of remaing  two).\n");
    }

    return 0;
}
answer Nov 24, 2014 by Arshad Khan
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.
0 votes

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 by Arshad Khan
Similar Questions
+2 votes

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

0 votes

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

0 votes

a and b are compared against
the threshold ‘TH’, and the nearest value is voted as output

+3 votes

e.g. Suppose I enter a string : Ram and Shyam likes Ramesh then the output should be Ramesh and Shyam likes Ram.
Here first word Ram is swapped with Ramesh .

...