Header Ads

ad728
  • New Updates

    Write a Program to Read Student Age


    Write a Program to Read Student Age

    मानलो कि हम Keyboard से कसी Student कि Age को Read करना चाहते है और उस Age में 10 जोड़कर Resultant मान को Screen पर Display करना चाहते है | इस समस्या का Algorithm निम्नानुसार बनाया जा सकता है |

     

    Algorithm :

    SIMPLE_INPUT (AGE, RESULT)

    Where :

         AGE is the age of student and

         RESULT is the modified age of the student

    1. START       [Start the Program.]

    2. Read AGE  [Get Age from keyboard.]

    3. PROCESS RESULT = AGE + 10

    4. PRINT RESULT

    5. END          [End the Program.]

     

     

    इसी Algorithm के आधार पर हम “C” भाषा में Program भी बना सकते है , जिसमें सबसे पहले हमें ये तय करना है कि हमेंकिस प्रकार का Data Computer की Memory में Process करने के लिए Store करना है | चूंकि Age एक Unsigned Type का मान होता है , जो की कभी भी Minus में या Negative Type में नहीं हो सकता है , साथ ही Age एक ऐसा मान होता है, जो बहुत ही छोटा होता है , क्योंकि किसी भी व्यक्ति कि Normal Age 100-150 साल से ज्यादा नहीं हो सकती है , इसलिए हम Age को store करने के लिए Unsigned Character Type का Variable Identifier कर सकते है , क्योंकि इस Data Type के Identifier की Range 0 से 255 तक होती है , जिसमें किसी भी Age से store हो सकती है |

    Program

     
    #include<conio.h>
    #include<stdio.h>
    main()
    {
    /*Declaration Section*/
    unsigned char age,result;
    
    /*Input Section*/
    printf("Enter Age of the Student:");
    scanf("%u",&age);
    /*Process Section*/
    result = age+10;
    
    /*Output Section*/
    printf("After 10year ,Student will be %u years old",result);
    getch();
    }

    हमें एक “C” Program में जितने भी Identifier को use करना होता है उन सभी Identifiers को Declaration Section में ही Declare करना जरुरी होता है | चूंकि हम हमारे इस Program में Keyboard से Input लेना चाहते है , इसलिए user को एक Message देकर ये बताना जरुरी होता है की Program को काम करने के लिए किस्म प्रकार के मान की जरुरत है |

    इसलिए Input Section में scanf( ) Function को use करने से पहले हमने एक printf( ) Statement को Use करके user को Student की Age input करने का Message दिया है | जब हम इस Program को Compile करके Run करते है , तो Program के Run होते ही Use को निम्नानुसार ये Message दिखाई देता है और Data प्राप्त करने के लिए Cursor Blink करने लगता है

    Enter Age of the Student:_

    यदि printf( ) statement द्वारा ये Message print ना करें , तो Output में Black Screen पर केवल Cursor Blink करता हुआ ही दिखाई देता है और user को पता ही नहीं लगता की उसे करना क्या है | जहां पर Cursor Blink कर रहा है , वहां पर user जो भी मान Input करता है , उस मान को scanf( ) Function scan करता है |

    मानलो user ने इस स्थान पर 15 input किया , तो scanf( ) Function इस 15 को scan करेगा और इस मान को उस age मान के variable के Memory Location पर Store करता है , जिसका नाम Age है , वैसे ही Input का काम समाप्त हो | उसके बाद Computer Program के अगले Statement को Execute करके Age में 10 जोड़ता है और इसके बाद के printf( ) Statement द्वारा Resultant मान को Screen पर निम्नानुसार Form में Print कर दिया जाता है |

    After 10 year, student will be 25years old

    जब ये Program पूरी तरह से Run हो जाता है , तब इसकी Output हमें निम्नानुसार प्राप्त होता है |

    Output

    Enter Age of the Student:15
    After 10year ,Student will be 25 years old
    

     

     

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728