C++ programing by soni kumari
Q.1.c++ "HELLO WORLD!"program
input:-
//your firstc++program
#include<iostream>
int main(){
std::cout<<"hello world!";
return 0;
}
hello world!
//your firstc++program
🔵 मतलब:
यह एक comment है, जो सिर्फ जानकारी देने के लिए है। C++ प्रोग्राम में किसी भी चीज़ को comment करने से प्रोग्राम पर कोई असर नहीं पड़ता।
यहां लिखा गया है: "आपका पहला C++ प्रोग्राम।"
cpp
Copy
Edit
#include<iostream>
🔵 मतलब:
यह लाइन C++ के input/output (I/O) कार्यों के लिए जरूरी हेडर फाइल iostream को शामिल करती है।
इस हेडर फाइल के जरिए हम std::cout और std::cin जैसे कमांड का उपयोग कर सकते हैं।
std::cout का उपयोग स्क्रीन पर डेटा दिखाने के लिए किया जाता है।
cpp
Copy
Edit
int main(){
🔵 मतलब:
यह C++ प्रोग्राम का मुख्य function है, जो execution (काम) शुरू करता है।
int का मतलब है कि यह function एक integer प्रकार का मान return करेगा (यहां पर 0)।
{} के बीच में प्रोग्राम के बाकी सभी instructions होंगे।
cpp
Copy
Edit
std::cout << "hello world!";
🔵 मतलब:
यह लाइन "hello world!" को स्क्रीन पर print करने का काम करती है।
std::cout — C++ में output stream को दिखाने के लिए उपयोग किया जाता है।
<< — यह stream insertion operator है, जो data को std::cout (output stream) में डालता है।
"hello world!" — यह वह string है, जो स्क्रीन पर दिखाई देगी।
cpp
Copy
Edit
return 0;
🔵 मतलब:
यह लाइन प्रोग्राम को सफलता पूर्वक खत्म करने के लिए 0 return करती है।
0 return करने का मतलब है कि प्रोग्राम में कोई error नहीं हुई है और सब कुछ ठीक है।
यह main function का अंत है।
🌟 Final Summary:
यह प्रोग्राम केवल स्क्रीन पर "hello world!" दिखाने का काम करता है, जो C++ प्रोग्रामिंग की शुरुआत के लिए एक पारंपरिक तरीका है।
include:-
using namespace std;
int main() {
int number;
cout << "Enter an integer: ";
cin >> number;
cout << "You entered " << number;
return 0;
}
Enter an integer: 5
You entered 5
नीचे आपके दिए गए C++ कोड का हर लाइन का हिन्दी में विवरण है:
cpp<iostream>👉 यह लाइन C++ की एक हेडर फाइल को शामिल करती है जिसका नाम है iostream। इसका उपयोग इनपुट (cin) और आउटपुट (cout) के लिए किया जाता है।
cppusing namespace std;👉 यह लाइन std नाम के namespace का उपयोग करने की अनुमति देती है, ताकि हमें std::cout या std::cin लिखने की ज़रूरत न पड़े।
cppint main() {👉 यह प्रोग्राम का मुख्य (main) फ़ंक्शन है जहाँ से प्रोग्राम की शुरुआत होती है। यह int टाइप का है, मतलब यह एक पूर्णांक (integer) मान लौटाता है।
cppint number;👉 यह एक integer वेरिएबल number को डिक्लेयर कर रहा है जिसमें उपयोगकर्ता द्वारा इनपुट किया गया अंक स्टोर किया जाएगा।
cpp cout << "Enter an integer: ";👉 यह लाइन स्क्रीन पर उपयोगकर्ता को एक संदेश दिखाती है: "Enter an integer: " ताकि वह कोई संख्या दर्ज करे।
cpp cin >> number;👉 यह लाइन उपयोगकर्ता से इनपुट लेती है और उसे number वेरिएबल में स्टोर करती है।
cpp cout << "You entered " << number;👉 यह लाइन स्क्रीन पर उपयोगकर्ता द्वारा दर्ज की गई संख्या को दिखाती है। उदाहरण: "You entered 5"
cppreturn 0;👉 यह लाइन बताती है कि प्रोग्राम सफलतापूर्वक समाप्त हो गया है। 0 का मतलब है कि कोई एरर नहीं हुई।
cpp}👉 यह main() फ़ंक्शन का अंत है।
अगर आप चाहें तो मैं इसका एक flowchart या विज़ुअल डायग्राम भी बना सकता हूँ — बताएं अगर आपको चाहिए?
input:-
#include<iostream>
using namespace std;
int main() {
int first_number, second_number, sum;
cout << "Enter two integers: ";
cin >> first_number >> second_number;
// sum of two numbers is stored in variable sum
sum = first_number + second_number;
// prints sum
cout << first_number << " + " << second_number << " = " << sum;
return 0;
}
output:-
Enter two integers: 4
5
4 + 5 = 9
#include<iostream>
📌 यह लाइन इनपुट (cin) और आउटपुट (cout) के लिए जरूरी हेडर फाइल iostream को प्रोग्राम में शामिल करती है।
cpp
Copy
Edit
using namespace std;
📌 यह हमें std::cout और std::cin की जगह सीधे cout और cin लिखने की सुविधा देता है।
cpp
Copy
Edit
int main() {
📌 यह main() फ़ंक्शन है, जो C++ प्रोग्राम की शुरुआत का बिंदु होता है।
cpp
Copy
Edit
int first_number, second_number, sum;
📌 यहाँ हमने तीन integer टाइप के वेरिएबल घोषित किए हैं:
first_number: पहली संख्या के लिए
second_number: दूसरी संख्या के लिए
sum: दोनों संख्याओं के योग (sum) को रखने के लिए
cpp
Copy
Edit
cout << "Enter two integers: ";
📌 यह उपयोगकर्ता को स्क्रीन पर संदेश देता है कि वह दो संख्याएँ दर्ज करे।
cpp
Copy
Edit
cin >> first_number >> second_number;
📌 यह उपयोगकर्ता से दो संख्याएँ इनपुट के रूप में लेता है और उन्हें first_number और second_number वेरिएबल्स में स्टोर करता है।
cpp
Copy
Edit
// sum of two numbers is stored in variable sum
sum = first_number + second_number;
📌 यह first_number और second_number को जोड़कर उनका योग sum वेरिएबल में स्टोर करता है।
cpp
Copy
Edit
// prints sum
cout << first_number << " + " << second_number << " = " << sum;
📌 यह आउटपुट दिखाता है जैसे:
5 + 3 = 8 — ताकि उपयोगकर्ता को पूरा जोड़ समझ में आए।
cpp
Copy
Edit
return 0;
📌 यह बताता है कि प्रोग्राम सफलतापूर्वक समाप्त हो गया है। 0 का मतलब है कि कोई त्रुटि नहीं हुई।
cpp
Copy
Edit
}
📌 यह main() फ़ंक्शन का समापन है।
अगर आप चाहें तो मैं इस कोड का हिन्दी कमेंट्स सहित संस्करण भी तैयार कर सकता हूँ। क्या आपको वह चाहिए?
output:-
Q.2 print number entered by user ?;
#include<iostream>
output:-
Q.3 program to add two interger?;
Q.4 compute quotient and remainder?;
input:-
#include<iostream>
using namespace std;
int main() {
int divisor, divident, quotient, remainder;
cout << "Enter divident: ";
cin >> divident;
cout << "Enter divisor: ";
cin >> divisor;
quotient = divident / divisor;
remainder = divident % divisor;
cout << "Quotient = " << quotient << endl;
cout << "Remainder = " << remainder << endl;
return 0;
}
output:-
Enter divident: 13
Enter divisor: 4
Quotient = 3
Remainder = 1
#include<iostream>
📌 यह लाइन इनपुट और आउटपुट के लिए जरूरी iostream हेडर फाइल को शामिल करती है।
cpp
Copy
Edit
using namespace std;
📌 यह हमें std::cout या std::cin के बजाय सीधे cout और cin लिखने की सुविधा देता है।
cpp
Copy
Edit
int main() {
📌 प्रोग्राम की शुरुआत main() फंक्शन से होती है।
cpp
Copy
Edit
int divisor, divident, quotient, remainder;
📌 यहाँ 4 integer वेरिएबल्स घोषित किए गए हैं:
divident — वह संख्या जिसे divide किया जाएगा।
divisor — वह संख्या जिससे divide किया जाएगा।
quotient — भाग करने का परिणाम (पूर्ण भागफल)।
remainder — भाग देने के बाद बचा हुआ हिस्सा (शेषफल)।
cpp
Copy
Edit
cout << "Enter divident: ";
📌 यह उपयोगकर्ता से divident (बड़ी संख्या) दर्ज करने को कहता है।
cpp
Copy
Edit
cin >> divident;
📌 उपयोगकर्ता द्वारा दर्ज किया गया divident को पढ़ता है।
cpp
Copy
Edit
cout << "Enter divisor: ";
📌 यह उपयोगकर्ता से divisor (जिससे भाग देना है) दर्ज करने को कहता है।
cpp
Copy
Edit
cin >> divisor;
📌 उपयोगकर्ता द्वारा दर्ज किया गया divisor को पढ़ता है।
cpp
Copy
Edit
quotient = divident / divisor;
📌 यह divident को divisor से भाग देता है और भागफल को quotient वेरिएबल में स्टोर करता है।
cpp
Copy
Edit
remainder = divident % divisor;
📌 यह divident को divisor से भाग देने पर बचा हुआ हिस्सा remainder में स्टोर करता है (modulus operator % का उपयोग किया गया है)।
cpp
Copy
Edit
cout << "Quotient = " << quotient << endl;
📌 यह भागफल को स्क्रीन पर दिखाता है।
cpp
Copy
Edit
cout << "Remainder = " << remainder << endl;
📌 यह शेषफल को स्क्रीन पर दिखाता है।
cpp
Copy
Edit
return 0;
}
📌 यह दर्शाता है कि प्रोग्राम सफलतापूर्वक समाप्त हो गया।
✅ उदाहरण आउटपुट:
mathematica
Copy
Edit
Enter divident: 17
Enter divisor: 5
Quotient = 3
Remainder = 2
अगर आप चाहें तो मैं इस कोड का Flowchart या Hindi comments version भी बना सकता हूँ। क्या आपको वह चाहिए?
📌 उदाहरण:
Q.16 wap to calculate average of numbers using arrays?;
input:-
#include<iostream>
using namespace std;
int main()
{
int exponent;
float base,result=1;
cout<<"Enter base and exponent respectively:";
cin>>base>>exponent;
cout<<base<<"^"<<exponent<<"=";
while(exponent !=0){
result*=base;
--exponent;
}
cout<<result;
return 0;
}
output:_
Enter base and exponent respectively:5
4
5^4=625
✅ उदाहरण:
⚠️ एक सुधार का सुझाव:
Q.17 wap to compute power manually?;
input:-
#include<iostream>
#include<cmath> // for pow()
using namespace std;
int main()
{
float base, exponent, result;
cout << "Enter base and exponent respectively: ";
cin >> base >> exponent;
result = pow(base, exponent);
cout << base << "^" << exponent << " = " << result;
return 0;
}
output:-
Enter base and exponent respectively: 5
4
5^4 = 625
Q.18.wap to convert binarty number to decimal?:
input:_
#include<cmath>
using namespace std;
//function prototype
int convert(long long);
int main(){
long long n;
cout<<"Enter a binary number:";
cin>>n;
cout<<n<<"in binary="<<convert(n)<<"in decimal";
return 0;
}
//function defination
int convert(long long n){
int dec=0,i=0,rem;
while(n !=0){
rem=n%10;
n/=10;
dec +=rem*pow(2,i);
++i;
}
return dec;
}
output:-
Enter a binary number:1001
1001in binary=9in decimal
Comments
Post a Comment