- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C Program to find sum of two numbers without using any operator

In this section we will see how to print the sum of two numbers without using any type of operator into our program.

This problem is tricky. To solve this problem we are using minimum width field of printf() statement. For an example if we want to put x number of spaces before “Hello” using printf() we can write this. Here printf() takes the width and then the character that will be printed. In this case we are writing blank space.

## Example Code

#include<stdio.h> main() { int x = 10; printf("%*cHello", x, ' '); }

## Output

Hello

Now let us see how this functionality can help us to get the result of sum in our code. We take x and y as input to get result of x + y. So using this procedure we will create x number of spaces followed by y number of spaces. Then we take the returned value of the printf() as our result. We know that the printf() returns the length of that string.

## Example Code

#include<stdio.h> int add(int x, int y) { int len; len = printf("%*c%*c", x, ' ', y, ' '); return len; } main() { int x = 10, y = 20; int res = add(x, y); printf("\nThe result is: %d", res); }

## Output

The result is: 30

- Related Questions & Answers
- Find the Sum of two Binary Numbers without using a method in C#?
- How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?
- Find XOR of two number without using XOR operator in C++
- C program to find sum and difference of two numbers
- 8085 program to sum of two 8 bit numbers without carry
- How to find the Sum of two Binary Numbers using C#?
- C++ program to Find Sum of Natural Numbers using Recursion
- Program to find remainder without using modulo or % operator in C++
- Add two numbers using ++ operator in C++.
- Java program to swap two numbers using XOR operator
- Find HCF of two numbers without using recursion or Euclidean algorithm in C++
- How to sum two integers without using arithmetic operators in C/C++ Program?
- C++ Program to Find GCD of Two Numbers Using Recursive Euclid Algorithm
- Maximum of four numbers without using conditional or bitwise operator in C++
- Java Program to Find Sum of N Numbers Using Recursion