The IGNOU MCS-011 Solved Question Paper PDF Download page is designed to help students access high-quality exam resources in one place. Here, you can find ignou solved question paper IGNOU Previous Year Question paper solved PDF that covers all important questions with detailed answers. This page provides IGNOU all Previous year Question Papers in one PDF format, making it easier for students to prepare effectively.
- IGNOU MCS-011 Solved Question Paper in Hindi
- IGNOU MCS-011 Solved Question Paper in English
- IGNOU Previous Year Solved Question Papers (All Courses)
Whether you are looking for IGNOU Previous Year Question paper solved in English or ignou previous year question paper solved in hindi, this page offers both options to suit your learning needs. These solved papers help you understand exam patterns, improve answer writing skills, and boost confidence for upcoming exams.
IGNOU MCS-011 Solved Question Paper PDF

This section provides IGNOU MCS-011 Solved Question Paper PDF in both Hindi and English. These ignou solved question paper IGNOU Previous Year Question paper solved PDF include detailed answers to help you understand exam patterns and improve your preparation. You can also access IGNOU all Previous year Question Papers in one PDF for quick and effective revision before exams.
IGNOU MCS-011 Previous Year Solved Question Paper in Hindi
Q1. (a) दी गई संख्या का उल्टा (reverse) ज्ञात करने और यह जांचने के लिए एक एल्गोरिदम लिखें और संबंधित फ्लोचार्ट बनाएं कि यह पैलिंड्रोम है या नहीं। (b) C में ऑपरेटरों की विभिन्न श्रेणियों को प्रत्येक के लिए एक उदाहरण के साथ सूचीबद्ध करें और समझाएं। (c) निम्नलिखित पैटर्न उत्पन्न करने के लिए C प्रोग्राम लिखें: * (d) रिकर्सिव फ़ंक्शन का उपयोग करके दी गई संख्या का फैक्टोरियल ज्ञात करने के लिए C प्रोग्राम लिखें।
Ans.
(a) संख्या को उलटने और पैलिंड्रोम की जांच के लिए एल्गोरिदम और फ्लोचार्ट
एल्गोरिदम:
- प्रारंभ करें।
- एक पूर्णांक चर num पढ़ें।
- एक अन्य चर originalNum में num का मान संग्रहीत करें।
- एक चर reverseNum को 0 से प्रारंभ करें।
- जब तक num > 0 है, तब तक निम्नलिखित चरणों को दोहराएं:
- digit = num % 10
- reverseNum = ( reverseNum * 10) + digit
- num = num / 10
- reverseNum को प्रिंट करें।
- यदि originalNum == reverseNum है, तो “संख्या पैलिंड्रोम है” प्रिंट करें।
- अन्यथा, “संख्या पैलिंड्रोम नहीं है” प्रिंट करें।
- समाप्त करें।
फ्लोचार्ट:
(b) C में ऑपरेटरों की श्रेणियाँ C प्रोग्रामिंग भाषा में ऑपरेटरों को निम्नलिखित श्रेणियों में वर्गीकृत किया गया है:
- अरिथमैटिक ऑपरेटर्स (Arithmetic Operators): इनका उपयोग गणितीय गणनाओं के लिए किया जाता है। उदाहरण: `int c = a + b;` (यहाँ `+` एक अरिथमैटिक ऑपरेटर है)। अन्य ऑपरेटर हैं `-`, `*`, `/`, `%` (मॉड्यूलो)।
- रिलेशनल ऑपरेटर्स (Relational Operators): इनका उपयोग दो मानों के बीच संबंध की तुलना करने के लिए किया जाता है। परिणाम हमेशा सत्य (1) या असत्य (0) होता है। उदाहरण: `if (a > b)` (यहाँ `>` एक रिलेशनल ऑपरेटर है)। अन्य ऑपरेटर हैं `<`, `>=`, `<=`, `==` (बराबर), `!=` (बराबर नहीं)।
- लॉजिकल ऑपरेटर्स (Logical Operators): इनका उपयोग दो या दो से अधिक शर्तों को संयोजित करने के लिए किया जाता है। उदाहरण: `if (a > 5 && b < 10)` (यहाँ `&&` (AND) एक लॉजिकल ऑपरेटर है)। अन्य ऑपरेटर हैं `||` (OR), `!` (NOT)।
- बिटवाइज़ ऑपरेटर्स (Bitwise Operators): ये बिट स्तर पर कार्य करते हैं। उदाहरण: `int c = a & b;` (यहाँ `&` (Bitwise AND) एक बिटवाइज़ ऑपरेटर है)। अन्य ऑपरेटर हैं `|` (Bitwise OR), `^` (Bitwise XOR), `~` (Complement), `<<` (Left Shift), `>>` (Right Shift)।
- असाइनमेंट ऑपरेटर्स (Assignment Operators): इनका उपयोग किसी चर को मान निर्दिष्ट करने के लिए किया जाता है। उदाहरण: `int a = 10;` (यहाँ `=` एक असाइनमेंट ऑपरेटर है)। अन्य ऑपरेटर हैं `+=`, `-=`, `*=`, `/=`।
- इनक्रीमेंट और डिक्रीमेंट ऑपरेटर्स (Increment and Decrement Operators): ये किसी चर के मान को 1 से बढ़ाते या घटाते हैं। उदाहरण: `a++;` (a का मान 1 से बढ़ाएं)। `b–;` (b का मान 1 से घटाएं)।
- कंडीशनल ऑपरेटर (Conditional Operator): यह एक टर्नरी ऑपरेटर है और if-else का संक्षिप्त रूप है। उदाहरण: `int max = (a > b) ? a : b;` (यदि a > b है तो max = a, अन्यथा max = b)।
(c) पैटर्न प्रिंट करने के लिए C प्रोग्राम #include
(d) रिकर्सिव फ़ंक्शन का उपयोग करके फैक्टोरियल के लिए C प्रोग्राम #include
Q2. (a) C में while लूप और do—while लूप के बीच क्या अंतर हैं? अपनी व्याख्या को स्पष्ट करने के लिए दोनों के लिए C कोड प्रदान करें। (b) एरे में दिए गए तत्व को खोजने के लिए एक C प्रोग्राम लिखें। यदि मान मौजूद है, तो एरे में उसकी स्थिति (इंडेक्स) के साथ उस मान को प्रिंट करें अन्यथा “तत्व नहीं मिला” प्रदर्शित करें। (c) उदाहरण के साथ कॉल बाय वैल्यू और कॉल बाय रेफरेंस के बीच अंतर करें।
Ans.
(a) `while` और `do-while` लूप के बीच अंतर
`while` और `do-while` दोनों ही C में लूपिंग कंस्ट्रक्ट हैं, लेकिन उनके काम करने के तरीके में एक महत्वपूर्ण अंतर है। मुख्य अंतर यह है कि शर्त का मूल्यांकन कब किया जाता है।
- While लूप (Entry-Controlled Loop):
- `while` लूप को एंट्री-कंट्रोल्ड लूप कहा जाता है।
- इसमें, लूप के बॉडी में प्रवेश करने से पहले शर्त की जाँच की जाती है।
- यदि शर्त शुरू में ही गलत (false) होती है, तो लूप की बॉडी एक बार भी नहीं चलेगी।
- सिंटेक्स: `while (condition) { // code to be executed }`
- Do-While लूप (Exit-Controlled Loop):
- `do-while` लूप को एग्जिट-कंट्रोल्ड लूप कहा जाता है।
- इसमें, लूप की बॉडी को कम से कम एक बार निष्पादित किया जाता है और उसके बाद शर्त की जाँच की जाती है।
- यह गारंटी देता है कि लूप की बॉडी कम से कम एक बार चलेगी, भले ही शर्त शुरू में गलत हो।
- सिंटेक्स: `do { // code to be executed } while (condition);`
उदाहरण कोड: While लूप का उदाहरण:
#include
#include
(b) एरे में तत्व खोजने के लिए C प्रोग्राम यह प्रोग्राम एक एरे में एक तत्व (एलिमेंट) की खोज (search) करता है। यदि तत्व मिल जाता है, तो यह उसकी स्थिति (इंडेक्स) प्रिंट करता है; अन्यथा, यह एक संदेश प्रदर्शित करता है। #include
(c) कॉल बाय वैल्यू बनाम कॉल बाय रेफरेंस फ़ंक्शन में पैरामीटर पास करने के ये दो तरीके हैं।
- कॉल बाय वैल्यू (Call by Value):
- इस विधि में, फ़ंक्शन को पास किए गए वास्तविक तर्क (actual argument) की एक प्रतिलिपि (copy) बनाई जाती है और फ़ंक्शन के औपचारिक पैरामीटर (formal parameter) को दी जाती है।
- फ़ंक्शन के अंदर पैरामीटर में किए गए कोई भी परिवर्तन मूल (original) तर्क को प्रभावित नहीं करते हैं।
- C में डिफ़ॉल्ट रूप से यही विधि अपनाई जाती है।
- कॉल बाय रेफरेंस (Call by Reference):
- इस विधि में, तर्क का पता (address) फ़ंक्शन को पास किया जाता है।
- फ़ंक्शन के अंदर, पैरामीटर मूल तर्क के पते को संग्रहीत करता है। इसलिए, पॉइंटर्स का उपयोग करके पैरामीटर में किया गया कोई भी परिवर्तन मूल चर (original variable) के मान को बदल देता है।
- C में, इसे पॉइंटर्स का उपयोग करके हासिल किया जाता है।
उदाहरण: दो संख्याओं की अदला-बदली (swapping)। कॉल बाय वैल्यू का उदाहरण (यह काम नहीं करेगा):
#include
#include
Q3. (a) C में एक प्रोग्राम लिखें जो छात्रों के प्रदर्शन को उनके अंकों के आधार पर विभिन्न श्रेणियों जैसे उत्कृष्ट, अच्छा, संतोषजनक, पास और फेल में वर्गीकृत करे। मानदंड: • उत्कृष्ट: अंक 90 से अधिक या बराबर • अच्छा: अंक 80 और 89 के बीच • संतोषजनक: अंक 70 और 79 के बीच • पास: अंक 40 और 69 के बीच • फेल: अंक 40 से कम (b) C प्रोग्रामिंग में प्रीप्रोसेसर डायरेक्टिव्स की अवधारणा की व्याख्या करें। तीन सामान्य रूप से उपयोग किए जाने वाले प्रीप्रोसेसर डायरेक्टिव्स के उदाहरण प्रदान करें और उनके कार्यों का वर्णन करें। (c) C में फ़ाइल हैंडलिंग का वर्णन करें। फ़ाइल खोलने के लिए विभिन्न एक्सेस मोड की व्याख्या करें।
Ans.
(a) छात्रों के प्रदर्शन को वर्गीकृत करने के लिए C प्रोग्राम
यह प्रोग्राम उपयोगकर्ता से छात्र के अंक लेता है और दिए गए मानदंडों के आधार पर `if-else if-else` लैडर का उपयोग करके प्रदर्शन श्रेणी प्रदर्शित करता है। #include
(b) C में प्रीप्रोसेसर डायरेक्टिव्स प्रीप्रोसेसर डायरेक्टिव्स C प्रोग्राम में ऐसे निर्देश होते हैं जो वास्तविक संकलन (compilation) शुरू होने से पहले प्रीप्रोसेसर द्वारा संसाधित (processed) किए जाते हैं। ये डायरेक्टिव्स `#` चिह्न से शुरू होते हैं। प्रीप्रोसेसर एक प्रोग्राम है जो स्रोत कोड को संशोधित करता है और कंपाइलर को आउटपुट भेजता है। प्रीप्रोसेसर डायरेक्टिव्स के मुख्य कार्य हैं:
- फ़ाइलों को शामिल करना (File Inclusion)
- मैक्रोज़ का विस्तार करना (Macro Expansion)
- सशर्त संकलन (Conditional Compilation)
तीन सामान्य प्रीप्रोसेसर डायरेक्टिव्स:
#include:- कार्य: इस डायरेक्टिव का उपयोग किसी अन्य फ़ाइल की सामग्री को वर्तमान स्रोत फ़ाइल में शामिल करने के लिए किया जाता है। इसका उपयोग आमतौर पर हेडर फ़ाइलों (जैसे
<stdio.h>,<string.h>) को शामिल करने के लिए किया जाता है, जिनमें मानक लाइब्रेरी फ़ंक्शंस की घोषणाएँ होती हैं। - उदाहरण:
#include <stdio.h> // मानक इनपुट/आउटपुट हेडर शामिल करता है#include "myheader.h" // उपयोगकर्ता-परिभाषित हेडर फ़ाइल शामिल करता है
- कार्य: इस डायरेक्टिव का उपयोग किसी अन्य फ़ाइल की सामग्री को वर्तमान स्रोत फ़ाइल में शामिल करने के लिए किया जाता है। इसका उपयोग आमतौर पर हेडर फ़ाइलों (जैसे
#define:- कार्य: इसका उपयोग मैक्रोज़ बनाने के लिए किया जाता है। एक मैक्रो एक पहचानकर्ता (identifier) या पैरामीटरयुक्त पहचानकर्ता होता है जिसे प्रीप्रोसेसर एक टोकन स्ट्रिंग से बदल देता है। इसका उपयोग आमतौर पर स्थिरांक (constants) को परिभाषित करने के लिए किया जाता है।
- उदाहरण:
#define PI 3.14159 // एक स्थिरांक को परिभाषित करता है#define MAX(a,b) ((a) > (b) ? (a) : (b)) // एक फ़ंक्शन-जैसा मैक्रोजब भी कोड में
PIआता है, तो प्रीप्रोसेसर उसे3.14159से बदल देता है।
#ifdef,#endif,#ifndef(Conditional Compilation) :- कार्य: ये डायरेक्टिव्स कोड के कुछ हिस्सों को शर्तों के आधार पर संकलित करने या छोड़ने की अनुमति देते हैं। यह डिबगिंग कोड को शामिल करने या विभिन्न ऑपरेटिंग सिस्टम के लिए कोड के विभिन्न संस्करण बनाने के लिए उपयोगी है।
- उदाहरण:
#define DEBUG // डिबग मोड को सक्षम करने के लिए#ifdef DEBUG printf("डिबग संदेश: चर x = %d\n", x);#endif // #ifdef ब्लॉक को समाप्त करता हैउपरोक्त कोड में, `printf` स्टेटमेंट केवल तभी संकलित किया जाएगा जब `DEBUG` मैक्रो को परिभाषित किया गया हो।
(c) C में फ़ाइल हैंडलिंग और एक्सेस मोड फ़ाइल हैंडलिंग C में एक तंत्र है जो हमें डिस्क पर संग्रहीत डेटा (फ़ाइलों) को स्थायी रूप से संग्रहीत करने, पुनः प्राप्त करने और संशोधित करने की अनुमति देता है। C में फ़ाइल संचालन `FILE` नामक एक संरचना (structure) का उपयोग करके किया जाता है, जिसे `stdio.h` हेडर फ़ाइल में परिभाषित किया गया है। फ़ाइल पर कोई भी ऑपरेशन करने से पहले, हमें `fopen()` फ़ंक्शन का उपयोग करके इसे खोलना होगा। `fopen()` एक पॉइंटर को `FILE` प्रकार की संरचना में लौटाता है, जिसका उपयोग फ़ाइल पर बाद के सभी ऑपरेशनों के लिए किया जाता है। विभिन्न फ़ाइल एक्सेस मोड: `fopen()` फ़ंक्शन दो तर्क लेता है: फ़ाइल का नाम और एक्सेस मोड। एक्सेस मोड निर्दिष्ट करता है कि फ़ाइल के साथ क्या किया जाएगा (पढ़ना, लिखना, आदि)।
"r"(Read):- फ़ाइल को केवल पढ़ने के लिए खोलता है।
- यदि फ़ाइल मौजूद नहीं है, तो `fopen()` `NULL` लौटाता है।
"w"(Write):- फ़ाइल को केवल लिखने के लिए खोलता है।
- यदि फ़ाइल मौजूद नहीं है, तो एक नई फ़ाइल बनाई जाती है।
- यदि फ़ाइल मौजूद है, तो इसकी सामग्री हटा दी जाती है (truncated)।
"a"(Append):- फ़ाइल को जोड़ने (append) के लिए खोलता है। डेटा फ़ाइल के अंत में जोड़ा जाता है।
- यदि फ़ाइल मौजूद नहीं है, तो एक नई फ़ाइल बनाई जाती है।
- मौजूदा सामग्री संरक्षित रहती है।
"r+"(Read/Write):- फ़ाइल को पढ़ने और लिखने दोनों के लिए खोलता है।
- यदि फ़ाइल मौजूद नहीं है, तो `fopen()` `NULL` लौटाता है।
- फ़ाइल पॉइंटर शुरुआत में रखा जाता है।
"w+"(Read/Write):- फ़ाइल को पढ़ने और लिखने दोनों के लिए खोलता है।
- यदि फ़ाइल मौजूद है, तो इसकी सामग्री हटा दी जाती है। यदि नहीं, तो एक नई फ़ाइल बनाई जाती है।
"a+"(Read/Append):- फ़ाइल को पढ़ने और जोड़ने के लिए खोलता है।
- यदि फ़ाइल मौजूद नहीं है, तो एक नई फ़ाइल बनाई जाती है।
- पढ़ने के लिए फ़ाइल पॉइंटर शुरुआत में होता है, लेकिन लिखने के लिए हमेशा अंत में होता है।
Q4. (a) निम्नलिखित कोड का आउटपुट क्या होगा? उस आउटपुट का कारण भी बताएं: #include<stdio.h> int main () { int x = 6, y=3, z; z = x– * y; printf (“%d, %d”, x, z); return 0; } (b) एक C प्रोग्राम लिखें जो यह जांचता है कि दी गई संख्या आर्मस्ट्रांग संख्या है या नहीं। (एक आर्मस्ट्रांग संख्या गणित में एक विशेष प्रकार की संख्या है। यह एक ऐसी संख्या है जो अपने अंकों के योग के बराबर होती है, प्रत्येक को एक घात n तक बढ़ाया जाता है, जहाँ n संख्या में अंकों की संख्या है, उदाहरण के लिए, यदि आपके पास 153 जैसी संख्या है, तो यह एक आर्मस्ट्रांग संख्या है क्योंकि 1³ + 5³ + 3³ = 153)। (c) एक एरे को परिभाषित करें। एरे को कैसे घोषित और आरंम्भ किया जाता है? इसे समझाने के लिए एक C कोड खंड लिखें।
Ans.
(a) कोड का आउटपुट और स्पष्टीकरण
कोड:
#include
5, 18 स्पष्टीकरण: इस कोड के आउटपुट को समझने के लिए, हमें C में पोस्ट-डिक्रीमेंट ऑपरेटर (`–`) और ऑपरेटर प्राथमिकता (operator precedence) को समझना होगा।
- प्रारंभ में, `x` का मान 6 है, `y` का मान 3 है, और `z` अघोषित है।
- कथन `z = x– * y;` निष्पादित होता है।
- यहाँ `x–` एक पोस्ट-डिक्रीमेंट ऑपरेशन है। इसका मतलब है कि `x` का वर्तमान मान (जो कि 6 है) पहले एक्सप्रेशन में उपयोग किया जाएगा, और फिर `x` का मान 1 से घटाया जाएगा।
- `*` (गुणा) ऑपरेटर की प्राथमिकता `–` (पोस्ट-डिक्रीमेंट) से अधिक होती है, लेकिन पोस्ट-डिक्रीमेंट का प्रभाव एक्सप्रेशन के मूल्यांकन के बाद होता है।
- तो, एक्सप्रेशन का मूल्यांकन `z = 6 * 3;` के रूप में होता है।
- इसलिए, `z` को मान `18` सौंपा जाता है।
- एक्सप्रेशन के मूल्यांकन के तुरंत बाद , `x` का मान 1 से घटकर `5` हो जाता है।
- अगला, `printf(“%d, %d”, x, z);` कथन निष्पादित होता है।
- इस बिंदु पर, `x` का मान `5` है और `z` का मान `18` है।
- इसलिए, `printf` फ़ंक्शन `5, 18` प्रिंट करेगा।
(b) आर्मस्ट्रांग संख्या की जांच के लिए C प्रोग्राम #include
(c) एरे: परिभाषा, घोषणा और आरंभीकरण परिभाषा: एक एरे (Array) एक ही डेटा प्रकार के तत्वों का एक निश्चित आकार का, अनुक्रमिक संग्रह है। ये तत्व सन्निहित (contiguous) मेमोरी स्थानों में संग्रहीत होते हैं। एरे का उपयोग एक ही नाम के तहत कई मानों को संग्रहीत करने के लिए किया जाता है, और प्रत्येक तत्व को एक इंडेक्स (या सबस्क्रिप्ट) का उपयोग करके एक्सेस किया जा सकता है। C में, एरे का इंडेक्स हमेशा 0 से शुरू होता है। घोषणा (Declaration): एक एरे को उसके डेटा प्रकार, नाम और आकार को निर्दिष्ट करके घोषित किया जाता है। आकार को वर्गाकार कोष्ठकों `[]` के भीतर निर्दिष्ट किया जाना चाहिए। सिंटेक्स: `data_type array_name[array_size];` उदाहरण: `int marks[50];` यह घोषणा `marks` नामक एक एरे बनाती है जो 50 पूर्णांक मानों को संग्रहीत कर सकती है। इन तत्वों को `marks[0]` से `marks[49]` तक एक्सेस किया जाएगा। आरंभीकरण (Initialization): एक एरे को उसकी घोषणा के समय आरम्भ किया जा सकता है। मानों की सूची को घुंघराले ब्रेसिज़ `{}` के भीतर प्रदान किया जाता है। C कोड खंड:
#include
Q5. (a) break स्टेटमेंट, continue स्टेटमेंट और goto स्टेटमेंट के बीच उदाहरणों के साथ अंतर स्पष्ट करें। (b) उदाहरणों के साथ C में किन्हीं पांच बिल्ट-इन स्ट्रिंग फ़ंक्शंस की व्याख्या करें। (c) स्ट्रक्चर और यूनियन के बीच अंतर स्पष्ट करें। अंतर को समझाने के लिए एक C कोड खंड लिखें।
Ans.
(a) `break`, `continue`, और `goto` स्टेटमेंट में अंतर
ये तीनों स्टेटमेंट C में प्रोग्राम के सामान्य अनुक्रमिक प्रवाह को बदलते हैं, लेकिन उनके कार्य और उपयोग अलग-अलग हैं।
breakस्टेटमेंट:- कार्य: `break` स्टेटमेंट का उपयोग किसी लूप (`for`, `while`, `do-while`) या `switch` स्टेटमेंट को तुरंत समाप्त करने के लिए किया जाता है।
- प्रवाह: जब `break` का सामना होता है, तो नियंत्रण तुरंत लूप या `switch` ब्लॉक के बाद वाले स्टेटमेंट पर स्थानांतरित हो जाता है।
- उदाहरण (लूप में):
for (int i = 1; i <= 10; i++) { if (i == 5) { break; // i=5 होने पर लूप समाप्त हो जाता है } printf("%d ", i);} // आउटपुट: 1 2 3 4
continueस्टेटमेंट:- कार्य: `continue` स्टेटमेंट का उपयोग लूप के वर्तमान पुनरावृत्ति (iteration) के शेष भाग को छोड़ने और अगले पुनरावृत्ति को शुरू करने के लिए किया जाता है।
- प्रवाह: जब `continue` का सामना होता है, तो लूप के अंदर के बाद के स्टेटमेंट को छोड़ दिया जाता है, और लूप अपने अगले पुनरावृत्ति (शर्त जांच/अपडेट के साथ) पर आगे बढ़ता है।
- उदाहरण:
for (int i = 1; i <= 5; i++) { if (i == 3) { continue; // i=3 के लिए printf को छोड़ देता है } printf("%d ", i);} // आउटपुट: 1 2 4 5
gotoस्टेटमेंट:- कार्य: `goto` स्टेटमेंट का उपयोग प्रोग्राम के प्रवाह को एक ही फ़ंक्शन के भीतर एक लेबल वाले स्टेटमेंट पर बिना शर्त स्थानांतरित करने के लिए किया जाता है।
- प्रवाह: यह नियंत्रण को प्रोग्राम में कहीं भी एक विशिष्ट लेबल पर “जंप” करने का कारण बनता है।
- उपयोग: इसके उपयोग से प्रोग्राम की पठनीयता और रखरखाव मुश्किल हो जाता है, इसलिए इसे आमतौर पर खराब प्रोग्रामिंग अभ्यास माना जाता है और इससे बचना चाहिए।
- उदाहरण:
int i = 1;start: // यह एक लेबल हैif (i <= 5) { printf("%d ", i); i++; goto start; // 'start' लेबल पर वापस जाएं} // आउटपुट: 1 2 3 4 5
(b) C में पांच बिल्ट-इन स्ट्रिंग फ़ंक्शंस C में स्ट्रिंग फ़ंक्शंस को `
strlen(str):- कार्य: यह एक स्ट्रिंग की लंबाई (वर्णों की संख्या) लौटाता है, जिसमें नल टर्मिनेटर (`\0`) शामिल नहीं है।
- उदाहरण:
char name[] = "Hello";int len = strlen(name); // len का मान 5 होगा
strcpy(dest, src):- कार्य: यह स्रोत स्ट्रिंग (`src`) को गंतव्य स्ट्रिंग (`dest`) में कॉपी करता है, जिसमें नल टर्मिनेटर भी शामिल है।
- उदाहरण:
char source[] = "World";char destination[10];strcpy(destination, source); // destination अब "World" है
strcat(dest, src):- कार्य: यह स्रोत स्ट्रिंग (`src`) को गंतव्य स्ट्रिंग (`dest`) के अंत में जोड़ता है (concatenate)।
- उदाहरण:
char dest[20] = "Hello ";char src[] = "World";strcat(dest, src); // dest अब "Hello World" है
strcmp(str1, str2):- कार्य: यह दो स्ट्रिंग्स की शब्दकोषीय (lexicographically) तुलना करता है।
- यदि `str1 < str2` है तो 0 से कम मान लौटाता है।
- यदि `str1 == str2` है तो 0 लौटाता है।
- यदि `str1 > str2` है तो 0 से अधिक मान लौटाता है।
- उदाहरण:
int result = strcmp("Apple", "Banana"); // परिणाम < 0 होगा
- कार्य: यह दो स्ट्रिंग्स की शब्दकोषीय (lexicographically) तुलना करता है।
strstr(haystack, needle):- कार्य: यह `haystack` स्ट्रिंग में `needle` सबस्ट्रिंग की पहली घटना को ढूंढता है।
- उदाहरण:
char *ptr = strstr("Programming is fun", "is");// ptr "is fun" स्ट्रिंग को इंगित करेगा
(c) स्ट्रक्चर और यूनियन में अंतर स्ट्रक्चर (Structure):
- यह एक उपयोगकर्ता-परिभाषित डेटा प्रकार है जो विभिन्न डेटा प्रकारों के आइटमों को एक साथ समूहित करने की अनुमति देता है।
- स्ट्रक्चर के प्रत्येक सदस्य को मेमोरी में अपना अलग स्थान आवंटित किया जाता है।
- एक स्ट्रक्चर का कुल आकार उसके सभी सदस्यों के आकारों के योग (या उससे अधिक, पैडिंग के कारण) के बराबर होता है।
- सभी सदस्य मानों को एक ही समय में संग्रहीत और एक्सेस किया जा सकता है।
यूनियन (Union):
- यह भी एक उपयोगकर्ता-परिभाषित डेटा प्रकार है जो विभिन्न डेटा प्रकारों के आइटमों को समूहित करता है।
- यूनियन के सभी सदस्य एक ही मेमोरी स्थान को साझा करते हैं।
- एक यूनियन का कुल आकार उसके सबसे बड़े सदस्य के आकार के बराबर होता है।
- एक समय में केवल एक सदस्य ही एक सार्थक मान रख सकता है। जब आप एक सदस्य को मान असाइन करते हैं, तो अन्य सदस्यों का डेटा अधिलेखित (overwritten) हो सकता है।
उदाहरण कोड: यह कोड खंड स्ट्रक्चर और यूनियन के बीच मेमोरी आवंटन में अंतर को प्रदर्शित करने के लिए `sizeof` ऑपरेटर का उपयोग करता है। #include
IGNOU MCS-011 Previous Year Solved Question Paper in English
Q1. (a) Write an algorithm and draw a corresponding flowchart to find the reverse of a given number and check if it is a palindrome or not. (b) List and explain various categories of operators in C along with an example for each. (c) Write a C program to generate the following pattern: * (d) Write a C program to find the factorial of a given number using a recursive function.
Ans. (a) Algorithm and Flowchart to Reverse a Number and Check for Palindrome
Algorithm:
- Start.
- Read an integer variable num .
- Store the value of num in another variable, originalNum .
- Initialize a variable reverseNum to 0.
- Repeat the following steps until num > 0:
- digit = num % 10
- reverseNum = ( reverseNum * 10) + digit
- num = num / 10
- Print reverseNum .
- If originalNum == reverseNum , print “The number is a palindrome”.
- Else, print “The number is not a palindrome”.
- End.
Flowchart:
(b) Categories of Operators in C
Operators in the C programming language are classified into the following categories:
- Arithmetic Operators: Used to perform mathematical calculations. Example: `int c = a + b;` (Here `+` is an arithmetic operator). Others are `-`, `*`, `/`, `%` (modulo).
- Relational Operators: Used to compare the relationship between two values. The result is always true (1) or false (0). Example: `if (a > b)` (Here `>` is a relational operator). Others are `<`, `>=`, `<=`, `==` (equal to), `!=` (not equal to).
- Logical Operators: Used to combine two or more conditions. Example: `if (a > 5 && b < 10)` (Here `&&` (AND) is a logical operator). Others are `||` (OR), `!` (NOT).
- Bitwise Operators: These operate on the bit level. Example: `int c = a & b;` (Here `&` (Bitwise AND) is a bitwise operator). Others are `|` (Bitwise OR), `^` (Bitwise XOR), `~` (Complement), `<<` (Left Shift), `>>` (Right Shift).
- Assignment Operators: Used to assign a value to a variable. Example: `int a = 10;` (Here `=` is an assignment operator). Others are `+=`, `-=`, `*=`, `/=`.
- Increment and Decrement Operators: These increment or decrement the value of a variable by 1. Example: `a++;` (Increment value of a by 1). `b–;` (Decrement value of b by 1).
- Conditional Operator: This is a ternary operator and is a shorthand for an if-else statement. Example: `int max = (a > b) ? a : b;` (If a > b, max = a, else max = b).
(c) C Program to Print the Pattern
#include <stdio.h>int main() { int i, j; int rows = 5; // Number of rows
// Outer loop for rows for (i = 1; i <= rows; i++) { // Inner loop to print '*' in each row for (j = 1; j <= i; j++) { printf("* "); } // Move to the next line printf("\n"); } return 0;}
(d) C Program for Factorial using a Recursive Function
#include <stdio.h>// Recursive function to calculate factoriallong long factorial(int n) { // Base Case: if n is 0 or 1, factorial is 1 if (n <= 1) { return 1; } // Recursive Step: n * factorial of (n-1) else { return n * factorial(n - 1); }}
int main() { int num; printf("Enter a number: "); scanf("%d", &num);
if (num < 0) { printf("Factorial is not defined for negative numbers.\n"); } else { printf("Factorial of %d = %lld\n", num, factorial(num)); }
return 0;}
Q2. (a) What are the differences between a while loop and a do—while loop in C ? Provide C code to illustrate your explanation for both. (b) Write a C program to search a given element in the array. If value exists, then print that value along with its position (index) in the array otherwise display “element not found”. (c) Differentiate between call by value and call by reference with an example.
Ans. (a) Differences between `while` and `do-while` loop
Both `while` and `do-while` are looping constructs in C, but they have a crucial difference in how they operate. The main distinction is when the condition is evaluated.
- While Loop (Entry-Controlled Loop):
- The `while` loop is called an entry-controlled loop .
- The condition is checked before entering the body of the loop.
- If the condition is false initially, the loop body will not execute even once.
- Syntax: `while (condition) { // code to be executed }`
- Do-While Loop (Exit-Controlled Loop):
- The `do-while` loop is called an exit-controlled loop .
- The body of the loop is executed at least once, and then the condition is checked.
- This guarantees that the loop body will run at least one time, even if the condition is initially false.
- Syntax: `do { // code to be executed } while (condition);`
Example Code:
While loop example:
#include <stdio.h>int main() { int i = 5; printf("While loop example:\n"); // This loop will not execute as the condition i > 5 is false. while (i > 5) { printf("Value of i: %d\n", i); i++; } printf("End of while loop.\n"); return 0;}// Output:// While loop example:// End of while loop.
Do-While loop example:
#include <stdio.h>int main() { int i = 5; printf("Do-While loop example:\n"); // This loop will execute once, then check the condition. do { printf("Value of i: %d\n", i); i++; } while (i > 5); printf("End of do-while loop.\n"); return 0;}// Output:// Do-While loop example:// Value of i: 5// End of do-while loop.
(b) C Program to Search an Element in an Array
This program searches for an element in an array. If the element is found, it prints its position (index); otherwise, it displays a message.
#include <stdio.h>int main() { int arr[] = {10, 25, 4, 42, 99, 76, 15}; int n = sizeof(arr) / sizeof(arr[0]); // Size of the array int element_to_find; int found = 0; // A flag to track if the element is found int index = -1; int i;
printf("Enter an element to search for: "); scanf("%d", &element_to_find);
// Loop through the array for (i = 0; i < n; i++) { if (arr[i] == element_to_find) { found = 1; // Set the flag to 1 index = i; // Store the index break; // Element is found, exit the loop } }
// Display the result if (found == 1) { printf("Element %d found at index %d in the array.\n", element_to_find, index); } else { printf("Element %d not found in the array.\n", element_to_find); }
return 0;}
(c) Call by Value vs. Call by Reference
These are two ways of passing parameters to a function.
- Call by Value:
- In this method, a copy of the actual argument being passed to the function is made and given to the formal parameter of the function.
- Any changes made to the parameter inside the function do not affect the original argument.
- This is the default method in C.
- Call by Reference:
- In this method, the address of the argument is passed to the function.
- Inside the function, the parameter stores the address of the original argument. Therefore, any change made to the parameter using pointers will change the value of the original variable.
- In C, this is achieved using pointers.
Example: Swapping two numbers.
Example of Call by Value (will not work for swapping):
#include <stdio.h>void swap(int x, int y) { int temp = x; x = y; y = temp; printf("Inside swap function: x = %d, y = %d\n", x, y);}int main() { int a = 10, b = 20; printf("Before swap: a = %d, b = %d\n", a, b); swap(a, b); printf("After swap: a = %d, b = %d\n", a, b); // Values of a and b will not change return 0;}
Example of Call by Reference (will work for swapping):
#include <stdio.h>void swap(int x, int y) { int temp = *x; x = y; *y = temp; printf("Inside swap function: x = %d, y = %d\n", x, y);}int main() { int a = 10, b = 20; printf("Before swap: a = %d, b = %d\n", a, b); swap(&a, &b); // Passing addresses of variables printf("After swap: a = %d, b = %d\n", a, b); // Values of a and b will be swapped return 0;}
Q3. (a) Write a program in C to classify students’ performance based on their marks into different categories such as Excellent, Good, Satisfactory, Pass and Fail. Criteria: • Excellent : Marks greater than or equal to 90 • Good : Marks between 80 and 89 • Satisfactory : Marks between 70 and 79 • Pass : Marks between 40 and 69 • Fail : Marks less than 40 (b) Explain the concept of preprocessor directives in C programming. Provide examples of three commonly used preprocessor directives and describe their functions. (c) Describe file handling in C. Explain various access modes for opening the file.
Ans. (a) C Program to Classify Students’ Performance
This program takes the student’s marks from the user and displays the performance category based on the given criteria using an `if-else if-else` ladder.
#include <stdio.h>int main() { int marks;
printf("Enter the student's marks (0-100): "); scanf("%d", &marks);
// Check to ensure marks are in a valid range if (marks < 0 || marks > 100) { printf("Invalid Marks! Please enter a value between 0 and 100.\n"); } else { // Classify performance based on marks if (marks >= 90) { printf("Performance: Excellent\n"); } else if (marks >= 80 && marks <= 89) { printf("Performance: Good\n"); } else if (marks >= 70 && marks <= 79) { printf("Performance: Satisfactory\n"); } else if (marks >= 40 && marks <= 69) { printf("Performance: Pass\n"); } else { printf("Performance: Fail\n"); } }
return 0;}
(b) Preprocessor Directives in C
Preprocessor directives are instructions in a C program that are processed by the preprocessor before the actual compilation begins. These directives start with a `#` symbol. The preprocessor is a program that modifies the source code and sends the output to the compiler.
The main functions of preprocessor directives are:
- File Inclusion
- Macro Expansion
- Conditional Compilation
Three Common Preprocessor Directives:
#include:- Function: This directive is used to include the contents of another file into the current source file. It is most commonly used to include header files (like
<stdio.h>,<string.h>) which contain declarations for standard library functions. - Example:
#include <stdio.h> // Includes the standard input/output header#include "myheader.h" // Includes a user-defined header file
- Function: This directive is used to include the contents of another file into the current source file. It is most commonly used to include header files (like
#define:- Function: This is used to create macros. A macro is an identifier or a parameterized identifier that the preprocessor replaces with a token string. It is commonly used to define constants.
- Example:
#define PI 3.14159 // Defines a constant#define MAX(a,b) ((a) > (b) ? (a) : (b)) // A function-like macroWhenever
PIappears in the code, the preprocessor replaces it with3.14159.
#ifdef,#endif,#ifndef(Conditional Compilation) :- Function: These directives allow sections of code to be compiled or skipped based on conditions. This is useful for including debugging code or creating different versions of code for different operating systems.
- Example:
#define DEBUG // To enable debug mode#ifdef DEBUG printf("Debug message: Variable x = %d\n", x);#endif // Ends the #ifdef blockIn the above code, the `printf` statement will only be compiled if the `DEBUG` macro has been defined.
(c) File Handling in C and Access Modes
File handling is a mechanism in C that allows us to permanently store, retrieve, and modify data stored on a disk (files). File operations in C are performed using a structure named `FILE`, which is defined in the `stdio.h` header file.
Before performing any operation on a file, we must open it using the `fopen()` function. `fopen()` returns a pointer to a structure of type `FILE`, which is then used for all subsequent operations on the file.
Various File Access Modes:
The `fopen()` function takes two arguments: the filename and the access mode. The access mode specifies what is to be done with the file (reading, writing, etc.).
"r"(Read):- Opens a file for reading only.
- If the file does not exist, `fopen()` returns `NULL`.
"w"(Write):- Opens a file for writing only.
- If the file does not exist, a new file is created.
- If the file exists, its contents are erased (truncated).
"a"(Append):- Opens a file for appending. Data is added to the end of the file.
- If the file does not exist, a new file is created.
- Existing contents are preserved.
"r+"(Read/Write):- Opens a file for both reading and writing.
- If the file does not exist, `fopen()` returns `NULL`.
- The file pointer is positioned at the beginning.
"w+"(Read/Write):- Opens a file for both reading and writing.
- If the file exists, its contents are erased. If not, a new file is created.
"a+"(Read/Append):- Opens a file for reading and appending.
- If the file does not exist, a new file is created.
- The file pointer is at the beginning for reading but at the end for writing, always.
Q4. (a) What will be the output of the following code ? Also, explain the reason for that output : #include<stdio.h> int main () { int x = 6, y=3, z; z = x– * y; printf (“%d, %d”, x, z); return 0; } (b) Write a C program to check if a given number is Armstrong number or not. (An Armstrong number is a special kind of number in Math. It’s a number that equals the sum of its digits, each raised to a power n, where n is the number of digits in the number for example, if you have a number like 153, it’s an Armstrong number because 1³ + 5³ + 3³ equals 153). (c) Define an array. How are arrays declared and initialized ? Write a C code segment to explain it.
Ans. (a) Code Output and Explanation
Code:
#include<stdio.h>int main () { int x = 6, y = 3, z; z = x-- * y; printf ("%d, %d", x, z); return 0;}
Output:
5, 18
Explanation: To understand the output of this code, we need to understand the post-decrement operator (`–`) and operator precedence in C.
- Initially, the value of `x` is 6, `y` is 3, and `z` is uninitialized.
- The statement `z = x– * y;` is executed.
- Here, `x–` is a post-decrement operation. This means that the current value of `x` (which is 6) will be used in the expression first, and then the value of `x` will be decremented by 1.
- The `*` (multiplication) operator has higher precedence than `–` (post-decrement), but the effect of post-decrement happens after the expression is evaluated.
- So, the expression is evaluated as `z = 6 * 3;`.
- Therefore, `z` is assigned the value `18`.
- Immediately after the expression is evaluated, the value of `x` is decremented by 1, making it `5`.
- Next, the `printf(“%d, %d”, x, z);` statement is executed.
- At this point, the value of `x` is `5` and the value of `z` is `18`.
- Hence, the `printf` function will print `5, 18`.
(b) C Program to Check for Armstrong Number
#include <stdio.h>#include <math.h> // For the pow() functionint main() { int number, originalNumber, remainder, n = 0; double result = 0.0;
printf("Enter an integer: "); scanf("%d", &number);
originalNumber = number;
// Count the number of digits while (originalNumber != 0) { originalNumber /= 10; ++n; }
originalNumber = number; // Reset originalNumber
// Calculate the result while (originalNumber != 0) { remainder = originalNumber % 10; result += pow(remainder, n); originalNumber /= 10; }
// Check if the number is an Armstrong number if ((int)result == number) { printf("%d is an Armstrong number.\n", number); } else { printf("%d is not an Armstrong number.\n", number); }
return 0;}
How the program works: 1. It takes a number from the user. 2. It calculates the number of digits (`n`) in the number using a loop. 3. Then, it raises each digit to the power of `n` and calculates the sum (`result`) using another loop. 4. Finally, it checks if the calculated sum is equal to the original number. If it is, the number is an Armstrong number. (c) Array: Definition, Declaration, and Initialization
Definition: An Array is a fixed-size, sequential collection of elements of the same data type. These elements are stored in contiguous memory locations. An array is used to store multiple values under a single name, and each element can be accessed using an index (or subscript). In C, the array index always starts from 0.
Declaration: An array is declared by specifying its data type, name, and size. The size must be specified within square brackets `[]`.
Syntax: `data_type array_name[array_size];`
Example: `int marks[50];` This declaration creates an array named `marks` that can store 50 integer values. The elements will be accessed from `marks[0]` to `marks[49]`.
Initialization: An array can be initialized at the time of its declaration. The list of values is provided within curly braces `{}`.
C Code Segment:
#include <stdio.h>int main() { // Declaration and initialization at the same time // The size can be omitted when an initializer list is provided int numbers[] = {10, 20, 30, 40, 50};
// Another example: Initialization after declaration float prices[4]; // Declaration prices[0] = 99.9; // Initialization prices[1] = 14.5; prices[2] = 25.0; prices[3] = 7.75;
printf("The first element of array 'numbers': %d\n", numbers[0]); printf("The third element of array 'prices': %.2f\n", prices[2]);
// Printing all elements using a loop printf("\nAll elements of array 'numbers':\n"); for (int i = 0; i < 5; i++) { printf("%d ", numbers[i]); } printf("\n");
return 0;}
Q5. (a) Differentiate between break statement, continue statement and goto statement, with examples. (b) Explain any five built-in string functions in C with examples. (c) Differentiate between Structure and Union. Write a C code segment to explain the difference.
Ans. (a) Difference between `break`, `continue`, and `goto` Statements
These three statements alter the normal sequential flow of a program in C, but their functions and use cases are distinct.
breakStatement:- Function: The `break` statement is used to terminate a loop (`for`, `while`, `do-while`) or a `switch` statement immediately.
- Flow: When a `break` is encountered, control is transferred to the statement immediately following the loop or `switch` block.
- Example (in a loop):
for (int i = 1; i <= 10; i++) { if (i == 5) { break; // Loop terminates when i is 5 } printf("%d ", i);} // Output: 1 2 3 4
continueStatement:- Function: The `continue` statement is used to skip the rest of the current iteration of a loop and begin the next iteration.
- Flow: When `continue` is encountered, subsequent statements inside the loop are skipped, and the loop proceeds to its next iteration (with condition check/update).
- Example:
for (int i = 1; i <= 5; i++) { if (i == 3) { continue; // Skips the printf for i=3 } printf("%d ", i);} // Output: 1 2 4 5
gotoStatement:- Function: The `goto` statement is used to transfer the program’s flow unconditionally to a labeled statement within the same function.
- Flow: It causes a “jump” in control to a specific label anywhere in the program.
- Usage: Its use makes programs difficult to read and maintain, so it is generally considered bad programming practice and should be avoided.
- Example:
int i = 1;start: // This is a labelif (i <= 5) { printf("%d ", i); i++; goto start; // Go back to the 'start' label} // Output: 1 2 3 4 5
(b) Five Built-in String Functions in C
String functions in C are declared in the `<string.h>` header file. Here are five common functions:
strlen(str):- Function: It returns the length (number of characters) of a string, not including the null terminator (`\0`).
- Example:
char name[] = "Hello";int len = strlen(name); // len will be 5
strcpy(dest, src):- Function: It copies the source string (`src`) into the destination string (`dest`), including the null terminator.
- Example:
char source[] = "World";char destination[10];strcpy(destination, source); // destination is now "World"
strcat(dest, src):- Function: It appends (concatenates) the source string (`src`) to the end of the destination string (`dest`).
- Example:
char dest[20] = "Hello ";char src[] = "World";strcat(dest, src); // dest is now "Hello World"
strcmp(str1, str2):- Function: It compares two strings lexicographically.
- Returns < 0 if `str1 < str2`.
- Returns 0 if `str1 == str2`.
- Returns > 0 if `str1 > str2`.
- Example:
int result = strcmp("Apple", "Banana"); // result will be < 0
- Function: It compares two strings lexicographically.
strstr(haystack, needle):- Function: It finds the first occurrence of the `needle` substring within the `haystack` string.
- Example:
char *ptr = strstr("Programming is fun", "is");// ptr will point to the string "is fun"
(c) Difference between Structure and Union
Structure:
- It is a user-defined data type that allows grouping of items of different data types together.
- Each member of the structure is allocated its own distinct location in memory.
- The total size of a structure is the sum of the sizes of all its members (or more, due to padding).
- All member values can be stored and accessed at the same time.
Union:
- It is also a user-defined data type that groups items of different data types.
- All members of the union share the same single memory location.
- The total size of a union is the size of its largest member.
- Only one member can hold a meaningful value at any given time. When you assign a value to one member, the data of other members may be overwritten.
Example Code Segment: This code segment uses the `sizeof` operator to demonstrate the difference in memory allocation between a structure and a union.
#include <stdio.h>// A structure definitionstruct ExampleStruct { int i; float f; char c;};
// A union definitionunion ExampleUnion { int i; float f; char c;};
int main() { printf("Memory difference between Structure and Union:\n\n");
printf("Size of struct: %lu bytes\n", sizeof(struct ExampleStruct)); // Output will typically be the sum of int(4) + float(4) + char(1) + padding // e.g., 12 bytes on a 4-byte alignment machine
printf("Size of union: %lu bytes\n", sizeof(union ExampleUnion)); // Output will be the size of the largest member (int or float), typically 4 bytes
union ExampleUnion u; u.i = 65; // Setting 'i' to 65 printf("\nUnion member values:\n"); printf("As u.i: %d\n", u.i); printf("As u.c: %c\n", u.c); // The lower byte of 'i' will be interpreted as ASCII value for 'A' (65) printf("As u.f: %f (meaningless value)\n", u.f);
return 0;}
Download IGNOU previous Year Question paper download PDFs for MCS-011 to improve your preparation. These ignou solved question paper IGNOU Previous Year Question paper solved PDF in Hindi and English help you understand the exam pattern and score better.
Thanks!
Leave a Reply