Arithmetic Operators कैसे काम करते हैं
Arithmetic operators जोड़ने, घटाने, गुणा करने, भाग देने, और बाकी बचा निकालने के लिए calculator buttons हैं। C# इनका उपयोग आपकी numbers से math करने के लिए करता है।
In this page:
Syntax
int result = a + b;
int result = a - b;
int result = a * b;
int result = a / b; // integer division truncates
int result = a % b;
Arithmetic Operators
C# basic arithmetic के लिए +, -, *, /, और % प्रदान करता है। Integer division किसी भी fractional part को truncate कर देता है, जबकि दो doubles को divide करना precision बनाए रखता है। % operator division का remainder return करता है।
Warning:
दो integers को divide करना, जैसे
7 / 2, 3 देता है, 3.5 नहीं — fractional result पाने के लिए एक operand को double में cast करें।उदाहरण: Arithmetic Operators
using System;
class Program
{
static void Main(string[] args)
{
int a = 7, b = 2;
Console.WriteLine(a + b);
Console.WriteLine(a - b);
Console.WriteLine(a * b);
Console.WriteLine(a / b); // integer division
Console.WriteLine(a % b); // remainder
Console.WriteLine((double)a / b); // fractional division
}
}
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- दो ints को divide करना और एक decimal result की उम्मीद करना, जबकि
7 / 23 है। - किसी integer को zero से divide करना, जो
DivideByZeroExceptionफेंकता है। - यह भूल जाना कि
%negative left operand के लिए एक negative result return करता है।
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: