- 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

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.

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\n", a + b); printf("c + d = %f\n", c + d); printf("a + c = %f\n", a + c); }

a = 5, b = 58; c = 6.32, d = 8.64;

a + b = 63 c + d = 14.960001 a + c = 11.320000

- Related Questions & Answers
- 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
- How to find the Sum of two Binary Numbers using C#?
- Find two numbers with sum and product both same as N in C++ Program
- Program to find two pairs of numbers where difference between sum of these pairs are minimized in python
- Find two numbers whose sum and GCD are given in C++
- C++ program to Find Sum of Natural Numbers using Recursion
- Program to find LCM of two Fibonnaci Numbers in C++
- Sum of two large numbers in C++
- C program to find sum and difference using pointers in function
- Program to find sum of first n natural numbers in C++
- Program to find GCD or HCF of two numbers in C++
- Program to find the maximum difference between the index of any two different numbers in C++
- Sum of two numbers modulo M in C++
- Find two numbers with sum and product both same as N in C++

Advertisements