- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 and difference of two numbers
Suppose we have two integer numbers a, b and two floating point numbers c, d. We shall have to find the sum of a and b as well as c and d. We also have to find the sum of a and c as well. So depending on the printf function style, output may differ.
So, if the input is like a = 5, b = 58 c = 6.32, d = 8.64, then the output will be a + b = 63 c + d = 14.960001 a + c = 11.320000
To solve this, we will follow these steps −
To print a + b, they both are integers, so printf("%d") will work
To print c + d, they both are floats, so printf("%f") will work
To print a + c, as one of them is integer and another one is float so we shall have to use printf("%f") to get correct result.
Example
Let us see the following implementation to get better understanding −
#include <stdio.h> int main(){ int a = 5, b = 58; float c = 6.32, d = 8.64; printf("a + b = %d
", a + b); printf("c + d = %f
", c + d); printf("a + c = %f
", a + c); }
Input
a = 5, b = 58; c = 6.32, d = 8.64;
Output
a + b = 63 c + d = 14.960001 a + c = 11.320000
- Related Articles
- C Program to find sum of two numbers without using any operator
- C++ program to find two numbers with sum and product both same as N
- The sum of squares two numbers is $26$ and difference is $8$. Find the numbers.
- Program to find two pairs of numbers where difference between sum of these pairs are minimized in python
- Find two numbers with sum and product both same as N in C++ Program
- C++ program to Find Sum of Natural Numbers using Recursion
- How to find the Sum of two Binary Numbers using C#?
- C program to find sum and difference using pointers in function
- The sum of two numbers is 8. If their sum is four times their difference, find the numbers.
- The sum of two numbers is 1000 and the difference between their square is 256000. Find the numbers.
- C++ program to find two numbers from two arrays whose sum is not present in both arrays
- Program to find sum of first n natural numbers in C++
- Program to find the maximum difference between the index of any two different numbers in C++
- Program to find LCM of two Fibonnaci Numbers in C++
- Find two numbers whose sum and GCD are given in C++

Advertisements