How to add two numbers without using arithmetic operators?

Answer Posted / roopali

#include<stdio.h>
int sum(int num1, int num2);
int main()
{
int num1, num2, result;
printf("Enter the number:");
scanf("%d%d",&num1,num2);
result=sum(num1,num2);
printf("The sum of two numbers is:%d",result);
return 0;
}

int sum(int num1, int num2)
{
int i;
for(i=0;i<num2;i++)
{
num1++;
}
return num1;
}

Is This Answer Correct ?    3 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How are variables declared in c?

593


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

621


What is unary operator?

654


What does nil mean in c?

667


What is main () in c?

581






Write the program with at least two functions to solve the following problem. The members of the board of a small university are considering voting for a pay increase for their 10 faculty members. They are considering a pay increase of 8%. Write a program that will prompt for and accept the current salary for each of the faculty members, then calculate and display their individual pay increases. At the end of the program, print the total faculty payroll before and after the pay increase, and the total pay increase involved.

2642


Difference between constant pointer and pointer to a constant.

606


What are the 4 types of organizational structures?

617


What are # preprocessor operator in c?

624


What is console in c language?

599


Can we access the array using a pointer in c language?

554


What is wild pointer in c?

600


What is exit() function?

556


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

895


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3112