c hindi tutorial

31
C hindi tutorial: if else  statement  Posted on अट  य 6, 2010 by hridayesh gupta आज  हभ if else statement का  उऩमोग  सीखगे . इससे  ऩहरे comparision operator  ाये   जानना  आवशमक  है  अत इसक  जानकाय  नीचे  द  जा  यह  है . operator का  भतर  है  चह (जै से  क +, – …). नीचे  दए  गए comparision operator Boolean output देते  , भतर  मे  मह  ताते   क  दमा  गमा  statement true है  मा false  < और > : जै से  क 3 > 1 का output है true जक 3 < 1 ka output है false. इसी  तयह 3 > 3 का output false होगा 3 से  डा 3 नहॊ  है . 3 < 3 का output बी false है .  <= और >= : मे  ऊऩय  वारे  क  तयह  ह   ऩयत 3 >= 3 औय 3 <= 3 का output true हो  जामे गा . मान  यहे  क <= क  जगह =< का  उऩमोग  नहॊ  कय  सकते . = का  चह > मा <  ाद ह  आना  चाहए .  == : मह  ताता  है  क  दो value याय   मा  नहॊ . मह int, char, आद  सबी  को compare कय  सकता  है . माद  यहे  क  मह = से  अरग  है . = assignment operator है  जो  क  ामे  औय  लरखे  variable को  दाई  औय  लरखी value देता  है , जक == दोन  औय  लरखे variable मा value को  compare कयता  है . अ  हभ  देखते   क  इनका  उऩमोग if else  से  कयते  . if statement का format नन  है . if(booelan expression1) { statement1; } else if(booelan expression2) { statement2; } ….. …. …. else { statementN; } अगय booelan expression1 का  भान true है  तो  लसपफ statement1 execute होगा . अगय booelan expression1 का  भान false है  तो  हभ booelan expression2 देखगे . अगय  मह true है  तो statement2 execute होगा . इसी  तयह  आगे  ढते  जाम गे . जहाॉ  बी  हभ booelan expression का  भान true त  

Upload: aksgoth

Post on 08-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 1/31

C hindi tutorial: if else statement Posted on अट ूय 6, 2010 by hridayesh gupta

आज  हभ if else statement का  उऩमोग  सीखगे. इसस ेऩहरे comparision operator के ाये भ जानना  

आवशमक  है अत् इसक  जानकाय  नीचे द  जा  यह  है. operator का  भतर  है चह (जसै ेक +, – …).

नीचे दए  गए comparision operator Boolean output देत ेह, भतर  मे मह  तात ेह क  दमा  गमा  

statement true है मा false   < और > : जसैे क 3 > 1 का output है true जक 3 < 1 ka output है false. इसी  तयह 3 > 3

का output false होगा 3 स ेडा 3 नहॊ है. 3 < 3 का output बी false है.   <= और >= : मे ऊऩय  वारे क  तयह  ह  ह ऩयत ु 3 >= 3 औय 3 <= 3 का output true हो  

जामगेा . मान  यहे क <= क  जगह =< का  उऩमोग  नहॊ कय  सकते. = का  चह > मा < के ाद  ह  आना  चाहए .   == : मह  ताता  है क  दो value याय  ह मा  नहॊ. मह int, char, आद  सबी  को compare कय  

सकता  है. माद  यहे क  मह = से अरग  है. = assignment operator है जो  क  ामे औय  लरखे 

variable को  दाई  औय  लरखी value देता  है, जक == दोन  औय  लरखे variable मा value को  

compare कयता  है. अ  हभ  देखते ह क  इनका  उऩमोग if else भ कैस ेकयत ेह. if statement का format नन  है. if(booelan expression1) { statement1; } else if(booelan expression2) { statement2; } ….. …. …. else { statementN; } अगय booelan expression1 का  भान true है तो  लसपफ statement1 execute होगा . अगय booelan

expression1 का  भान false है तो  हभ booelan expression2 देखग.े अगय  मह true है तो statement2

execute होगा . इसी  तयह  आग ेढत ेजामगे. जहाॉ बी  हभ booelan expression का  भान true ात  

Page 2: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 2/31

होगा  केवर  उसी  स ेसधत statement execute होगा , कोई  औय  नहॊ. अगय  कोई booelan

expression true नहॊ है तो else के अदय  जो statement है वो execute होगा . इसे एक  उदहायण  के 

वाया  सभझत ेह. नीचे दए  गए example भ दए  गए total marks औय obtained marks के अन ुसाय  हभ percentनकारगे औय percent के  आधाय  ऩय grade print कयग.े #include <stdio.h> 

int main() { 

int total_marks = 500; int obtained_marks = 272; 

int percent = obtained_marks*100/total_marks; 

if (percent >= 60) { printf ("Congrats!! You passed in 1st division.\n"); printf ("Your percentage is %d.\n",percent); 

} else if (percent >= 45) { 

printf ("You passed in 2nd division.\n"); printf ("Your percentage is %d.\n",percent); 

Page 3: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 3/31

else if (percent >= 33) { printf ("You just passed in 3rd division.\n"); printf ("Your percentage is %d.\n",percent); 

} else { 

printf ("Sorry! you failed.\n"); printf ("Your percentage is %d.\n",percent); 

scanf ("%s"); return 1; 

} ऊऩय  दखाई  गई values के अन ुसाय percent क value 54 आएगी .(महाॉ गौय  कयने रामक  ात  मह  है 

क percent क value 54.4 नहॊ आएगी  मक  हभने अऩने program को int नामा  है. ) च ूॊक  

percent 60 स ेछोटा  है अत् ऩहर  वार condition (percent >= 60) का result false आएगा  आएगा  

इसलरए  हभ  अगर  वार condition (percent >= 45) check कयगे जो  क true है अत् न  ऩय  

print होगा  You passed in 2nd division. Your percentage is 54 अ  च ूॊक  कोई  बी condition true होन ेऩय  उसक े अदय  वारे statement ह execute होते ह. अत् मह  

program औय  क ु छ print नहॊ कयेगा . महाॉ एक  ात  मान  देने रामक  है क  हभने printf के अदय \n

का  उऩमोग  कमा  है ऩयत ु मह print नहॊ ह ुआ , मक \n का  भतर  है new line character अथाफत \n

के ाद  जो  बी print होगा  वो  अगर line भ print होगा . महाॉ आऩ \n को  हटाकय run कय औय output

देख. इसी  तयह  दए  गए example भ obtained_marks क  अरग  अरग value यख  कय program को  

Page 4: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 4/31

run कय औय output को  मान  स ेदेख. अगय  इससे सॊधत  कोई  सवार  आऩक े ऩास  है तो  नीचे 

comment के भामभ  स ेऩ ूछ  सकते ह.   basic example.

#include <stdio.h> int main() { int percent = 45; if(percent >=

33) { printf("Congrats!! You passed.\n"); } else { printf("Sorry.!

you failed\n"); } scanf("%s"); return 1; }

ऊपर    ग example   percent  value change र  र 

program  run र   .  पऱ य check रग   percent

 value 33   रर  य  य   [if(percent >= 33)] अगर     

 screen पर print ग  

Congrats!! You passed.

अय print ग (else)

Sorry.! you failed

  य  र       { }   अर      ऱ    प,    ऱ  

      .  example     ग   speed ऱग और  अगर  य 60  य    warning print र ग अय       र ग.

#include <stdio.h> int main() { int speed = 65; if(percent > 60)

{ printf("Warning: Speed is in danger zone.\n"); } else { }

scanf("%s"); return 1; }

  speed  value ऱ  ऱर program run र और   य  

Page 5: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 5/31

Page 6: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 6/31

ऱ    प  पर        य screen पर  य print रग .

     variable i define य             रग    

 input ऱग.     ऱ line   य   य  ऱ   scanf("%d", &i);

scanf printf   र      र  .   पऱ argument "%d"   

    ऱ    printf      ,   र    य     

input   int ऱग.  र argument &i य        input ऱग   

 variable   store ग . (य variable  पऱ &   ऱग  

य       र  ग  ग  pointer   र   प ग.)अगर  प screen   25 enter र ग  i    25   यग .     

ऱ program पऱ ऱ    अ र  प          -

screen पर    य   print य     प enter य   .

य य  य  र % ग     ऱ       . अ   य  

2     ग   पर  य   0       print य    Number

is even अय  य print य    Number is odd.

र program   अ    scanf ऱ   र : अगर  प windows   

program run र  र      ऱ window  ऱ    output

   पर    program      य  ऱ window     

  . अ    scanf ऱ  ऱ window      य    

र input  wait र  . अगर  य  ऱ ग  program    run र  ऱ window     यग      अप program   

output      पग.

अ     Array   र  .

 variable   र            र variable  value store र  

   पर  variable define र य  य           

Page 7: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 7/31

 type  value store रग integer, character etc. Array    

अ value store र    . अगर  प 100 int store र     

  array   र    .   example   य          अ variable Array    store र  .

   ग example   0 9   य  square array   store

र ग और    print र ग. पऱ  program  run र   .

#include <stdio.h> int main() { int i = 0; int arr[10]; for(i = 0; i < 10;

i++) { arr[i] = i*i; } for(i = 0; i < 10; i++) { printf("square of %d is

%d\n", i, arr[i]); } scanf("%d", &i); }

अ     . int arr[10]; arr variable define र  र    10 int

store र    . य  र य   ऱ int store र    . य र int

  number store र  . य  र    numbering 0 start

       10 int  Array arr   पऱ int arr[0] पर  ग ,  र  

arr[1] पर ... ऊपर   arr  size 10 र   अ य 10 int(arr[0]  

arr[9])  store र    .      program   प      

  . for loop   अर (   10 र run ग )     पऱ  र  

य ग  i    0 ग  अ arr[0] (arr array   पऱ int)   0   

यग    र  ग      for loop   अर  अ  र  य ग 

 array arr   अ int(arr[9])   81   यग .   र  अगऱ for

loop    arr          print र  र  .

अ    array   य     access र   ऱ  ऊपर  

  अ र for loop   यग  र  .

Page 8: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 8/31

 

Wednesday, October 27, 2010

   while loop   पयग  र   ग.    boolean

statement य    .      value true       loop

  अर  ऱ statement run  र  .         ग example

   . while loop   पयग  र    र  र   1 10     

य   square print र ग #include <stdio.h> int main() { int i=1; int sq; while(i<=10) { sq =

i*i; printf("square of %d is %d.\n", i, sq); i = i+1; } scanf("%d", &i);return 1; }

ऊपर    ग program   i   र  value 1 .    while loop

 boolean statement i<=10    true  य i  value 1 ,

ऱ loop   अर  ऱ र statement execute   य ग. य      

 loop   अर i  value 1   र  . र   boolean statement true  यग  य i   value 2   गय  .   र  ग  र ग.  i

 value 11   यग   boolean statement false   ग  और    

while loop  र    य ग.  program   ऱ  र   . य 1 10

    य   square print रग .

अगऱ ऱ     string   पयग  र   ग और       use

र     interesting example  ग.

Saturday, October 30, 2010

Page 9: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 9/31

C language tutorial in hindi   ग        string   र   

 ग.  पऱ Array और char type variable   र     

य  .What is String

 char variable   र            य variable       

अर (letter)  store र   . अ  अगर    ऱ          

word(     य  अर   ऱर    ग )  store र     

   र ग?   ऱ   char    array य ग,   array   

  र       य variable store र     अ  help   word य sentence store र    . examples  help   word

"hindi"  store र और   print र  3 अऱग  अऱग  र   

  और  य    important  .#include <stdio.h> int main() { char w[6]; w[0] = 'h'; w[1] = 'i'; w[2]

= 'n'; w[3] = 'd'; w[4] = 'i'; w[5] = '\0'; printf("Word we stored is %s

\n", w); printf("1st letter of array is %c \n", w[0]); scanf("%s", w);

return 0; }

ऊपर    ग program  run र output  .    print रग  Word we stored is hindi

1st letter of array is h

अ        य      र  . char    array   

  6 char     .       र    array   valuesऱ     र        पऱ   पर h र i   र   

value ऱ     . य     अ   w[5] पर \0     2 char

  1 char ,     य     य   word   अ letter .

  र   \n line break character      अगऱ  ऱ    print

     र \0      ऱ letter read य print   .   

  ग     ऱ   6 char ऱ array य   र hindi   

Page 10: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 10/31

  5 char    . अ    य    य     string  print र   ऱ  

%s  use य    . w  string   w[0], w[1]...  char

 . पऱ ऱ printf statement   string w  print य   ऱ %s use य      र ऱ printf statement   char w[0]  print

य   ऱ %c  use य  .

अ   ऱ program य   ऱ  ऱ  पऱ ऱ   र    

र  .#include <stdio.h> int main() { char w[] = {'h', 'i', 'n', 'd', 'i', '\0'};

printf("Word we stored is %s \n", w); printf("1st letter of array is %c\n", w[0]); scanf("%s", w); return 0; }

  पऱ ऱ     difference         line   array

 define   र  र   और   values   ऱ  र     र     

variable int      line   define र और value    ऱ int

x = 1; ऱ  .   र  array define र य array  length

   प (अ  य  ऱ  प   array    element

य ग)

गऱ  र char w[6] = {'h', 'i', 'n', 'd', 'i', '\0'};

  र char w[] = {'h', 'i', 'n', 'd', 'i', '\0'};

अ    और program        ऱ  ऱ  पऱ ऱ   र    र  .#include <stdio.h> int main() { char w[] = "hindi"; printf("Word we

stored is %s \n", w); printf("1st letter of array is %c \n", w[0]);

scanf("%s", w); return 0; }

 program   ऊपर  ऱ   1 line   difference य     य char

array    ऱ shortcut  use य  . य shortcut char

Page 11: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 11/31

array    ऱ use   .char w[] = "hindi";

य  ऱ   char array w   यग .  array   पऱ element

w[0] 'h',  र element w[1] 'i' ....   यग . अ element w[5] '\0'   

यग .  syntax(र )   \0  ऱ  प .

अ    ऱ string      , पर  ग      पयग    .

य  य  पर recall र र ग और      र र   र    

र ग.

 blog   र     ऱ  प         ग  रग .

      ऱ  अप Reply य पर   . अगऱ ऱ     function  

र    ग       important .

        अऱग  अऱग  य  र  र  र   ऱ function

 use र  . य  र  if else statement ऱ topic      

program ऱ       total marks और obtained marks   र  पर  

percent और division ऱ  र print र   . अ  अगर    5

students   ऱ percentage और division ऱ       र  य  

     पऱ ऱ program   total marks और obtained marks   र  

र modify र  और  र  र program  compile र run र . पर  

    time ऱग  यग .   और  र  य    program     

ग   percentage ऱ  र division print र    5 र copy-

Page 12: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 12/31

paste र .

    र    अ  र   function  use.     

 function ऱ ग  total marks और obtained marks  पर      percentage . अ percentage print र  program     ,

   division print र  program    ग.

 ऱ   program   य   function define य  .

पर   run   र य  य run  ग .    function call र 

और run र    र   ग.

int get_percent(int total marks, int obtained marks) {int percent = obtained_marks*100/total_marks;

return percent;

}

 पऱ int ऱ  गय     य      function   र    

    return रग .  example   function int type       

return रग .    function     ऱ  ,   य पर  get_percent .    ()   function input variable ऱ     

parameter य argument    input variable ऱ य  य    

  प        type     और    function   अर    

   access र ग. य  input int  .  function      

 input    , य  र  अगर     input      ()  

अर       ऱ. य 2 input   ग   .    {}   अर    

ऱ    function   रग . य    ग input   पयग  

र percent ऱ  . अ    return र  .

     ऱ    int य    र      य function int type  value

  ग (return रग ). अ    return ऱर   percent return र  र 

   int type     . अगर return statement         ऱ       

Page 13: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 13/31

run  ग , य return   function   य  प  ऱग       

य value return र   और function  value return र    य  

      .अ  य        function  use  र ग.    ग  

program  run र   .#include <stdio.h>

int get_percent(int total_marks, int obtained_marks) {

int percent = obtained_marks*100/total_marks;

return percent;

}int main() {

int percent;

percent = get_percent(500, 360);

printf("Percent is %d\n", percent);

percent = get_percent(500, 340);

printf("Percent is %d\n", percent);

scanf("%d", &percent);

return 0;}

 पऱ  function define य        get_percent,   

int type  value return रग  और 2 int type parameter ऱग     

  ऊपर          . र  

main()   अर   program run  start          अ    

 य  . main   अर  पऱ int type  percent variable define

य  .    get_percent function call य     ऊपर define

य   .  function    2 parameter 500 और 360    . य 

parameter      important .  function  call र पर  ऊपर  

ऱ function run        यग , total_marks  value 500

और obtained_marks  value 360 ऱ  यग .  values basis पर  

Page 14: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 14/31

get_percent percent  value 80 ऱर return र  ग .percent = get_percent(500, 360);

य  ऱ पर get_percent    return रग   percent   store

यग .      main()   अर   percent print र  र  .   

र    र  और get_percent function  call र   value    

percent variable   store र print र  र  .

य    note र   main    function       parameter

 ऱ (ऱ main() ऱ   ()        ऱ ) और int return

र   ऱ    अ    र  र return 0; ऱ   र  .        C program run र        main function call   

. main   अर       function call र      sequence   call

  . अ     main function   अ    प       program

finish     . अगर  प     program  run र  main

function               र   error ग   main method not

found.

अ      और program     division  print र. run

र   .#include <stdio.h>

void get_percent(int total_marks, int obtained_marks) {

int percent = obtained_marks*100/total_marks;

if(percent >= 60) {printf("Congrats!! You passed in 1st division.\n");

printf("Your percentage is %d.\n",percent);

}

else if(percent >= 45) {

printf("You passed in 2nd division.\n");

printf("Your percentage is %d.\n",percent);

}

else if(percent >= 33) {

Page 15: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 15/31

printf("You just passed in 3rd division.\n");

printf("Your percentage is %d.\n",percent);

}

else {

printf("Sorry! you failed.\n");

printf("Your percentage is %d.\n",percent);

}

}

int main() {

get_percent(500, 360);

get_percent(500, 340);

int abc;scanf("%d", &abc);

return 0;

}

 example   get_percent function division  print र  र  .   

पऱ ऱ function   difference य     य function         

print र  र   ऱ main   अऱग   print र   र   .

     void ऱ  गय     ऱ     य function    return

 रग , ऱ main   function    call य  गय  ,   

पऱ ऱ example    value function return र  र       

variable   store र  र .Exercise:

1.  function print_month ऱ    int parameter      

  number ग  और   function     print र  .  

अगर     10     October print र  .  function       

return  र   , print र   .      function

 main  अऱग  अऱग parameter call र .

Page 16: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 16/31

2. ऊपर  ऱ program   main   पऱ scanf  use र input ऱ और  

 input parameter    print_month call र .

अगऱ ऱ          और example  ग.

Wednesday, November 17, 2010

   function      examples   र variable scope   र   

 ग. अगर  प C function और C variables         पऱ    प  ऱ.

What is scope

C    variable scope   ऱ  य      variable   

declare य define र       पर   value प    .

अगर    function   अर   variable x define य       function   अर      variable  read/write र     पर  

  अय function   अर  . अगर   loop   अर   variable

define य      loop   अर      variable  read/write

र     पर    र  .

        .    {...}   अर define य  गय  

variable   अर    read/write य       पर   

र  .       ग example   ग.

   ग program      register य ग       

add र     और       print र    . program  run

र पर   Menu यग    र     register   name add

र     य register        print र    .#include <stdio.h>

Page 17: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 17/31

char list[10][20];

int length = 0;

void add_name() {

if(length >= 10) {

printf("list is full\n");

return;

}

printf("Enter the name: ");

scanf("%s", list[length]);

length = length + 1;

printf("name added\n");

}

void print_list() {int i = 0;

for(i=0; i < length; i++) {

int serial_no = i + 1;

printf("%d : %s\n", serial_no, list[i]);

}

}

int main() {

int input = 0;while(input != 3) {

if(input == 0) {

printf("0 - Print this menu\n");

printf("1 - add name to list\n");

printf("2 - print list\n");

printf("3 - quit program\n");

}

else if(input == 1) {add_name();

}

else if(input == 2) {

print_list();

}

else {

printf("Wrong Input, try again\n");

}

Page 18: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 18/31

scanf("%d", &input);

}

}

ऊपर    ग program  run र पर        menu print ग    

य  ग    य enter र पर  य  ग . List    add र  

ऱ 1 press र enter र ,     य  प ग         add

र  .  type र enter र . र    र   add र      

र   1 enter र . List print र   ऱ 2 Enter र . पऱ   

program  run र    र        य      र  .

अ       य      र  .       2 variable list और  

length declare य  .    य  variable  function   अर   

   र    ऱ       function य loop   अर   

read/write र    . य  य    variable  {}   अर  

declare य ग     र    access  य   ,  अर    access य     .

अ     char list[10][20]; पर . अगर  र  char list[10];     

  ऱ  य     list  array   10 char     .

पर  य char list[10][20];    ऱ    list  array   

20 char ऱ 10 array      . य 10 char   ग 10 array

ग  और  र   array 20 char ऱ  ग .

अगर int a[2][3]       र       .a = { {1,2,3} , {4,5,6} };

य पर a   अर 2 array        array a[0]   और   a[1]  .

   array   3 3 int     .

char list[10][20];  use  store र   ऱ  र ग.          

Page 19: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 19/31

   string   char array   store र  . य list   10 char

array       ऱ     10  store र    . र    

array   20 char      ऱ       store र      20 य    letter  .  र variable length य       

currently list       ,        0 .

   add_name function   call र पर  य list       

add र  ग . पऱ  check र   अगर list   10            

return  use र function      र    , अय scanf   

use र list variable     read र  ऱ  . य     scanf   पऱ argument "%s"     string read र   ऱ   र  

argument char array    . list[0], list[1], list[2] ... list[19]   

20 char ऱ array  .

list    add       length 1     . list[length]   list   

  

अगऱ  

ऱ  

ग  

 

ग  

य  

   

 list

ऱ  

 

ऱ  

list[length] (length=0) ऱ char array ऱ  .    list[0]   add

    length = 1   यग , अ list[length] (length = 1) ऱ  

array ऱ  .

   print_list function define य  , length  य  प  ऱ  

    list           for loop print र  ऱ  . य 

for loop   अर   variable serial_no define य      loop  र   access  ग .

अ    main function   program run  start   . if-

else statement  use र input variable  value according list   

 add र  , list print र  , menu print र  .   प र if-else   

while loop   अर  ऱ  गय  ,        run ग     input

Page 20: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 20/31

 value 3     . while loop     पऱ input variable   

scanf  use र input read र  , अगर input 3   while loop

   program finish   यग otherwise while loop   अर  र   र input value according if-else  use र list    add

र  , list print र  , menu print र   और  र   input variable

  scanf  use र input read र  .

Sunday, November 21, 2010

     important keywords break और continue  use र  

 ग,  loops (for loop, while loop, switch case)         

    .

use of break in c/c++

c/c++    loop           र   र  ऱ   ऱ  

break  use य    . र    ऱ    ऱ   int array   

   number       ,   ऱ for loop  use र 

array   र   element  check र ग    number     .

य for loop     ऱ  रग        प र array check  र  

ऱ, पर                  number ऱ  य    

र    for loop   र loop  र    .   ऱ break   

use र ग. for loop    while loop      र     ऱ    

Page 21: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 21/31

break  use र  .

    ग example    .    100 200     

पऱ  य search र ग  21      य.

#include <stdio.h>

int main() {

int i;

for(i=100; i<=200; i++) {

if(i%21 == 0) {

printf("1st such number is %d\n", i);break;

}

}

scanf("%d", &i);

return 0;

}

य for loop   अर if statement . प  य  ऱ     % य  

     पऱ  य     र    ग   पर    य  ग .   

य    ऱ i%21  value 0   अ   21     

for loop   i       ऱ   if   अर   य ग (य   

           य for loop   i 100 200   र     

ऱ for loop   अर  ऱ र statement run ग.)      if   अर  

ऱ statement run  ग पर    i  value 105(21   )

ग if   अर  ऱ य ग और break run   यग  और for loop   

  यग . ऱ finally for loop   अर  ऱ statement i 100  

105    value   ऱ   run   पग य i=105      

Page 22: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 22/31

break run    र for loop     यग .

  र c/c++   while loop           र   ऱ break   

use र  . switch case statement    break  use         .

use of continue in c/c++

          loop   (for loop, while loop)       

statement र  र run  र  .    loop   अ    य   

  र         और        loop       पर    र  loop   अर   run   र     य     य और loop   अगऱ  

iteration start   य,   ऱ continue  use र  .     

  ग example    .  example    array      number

  ग   .  continue  use र odd numbers (  य )

print र ग.

#include <stdio.h>

int main() {

int arr[] = {1,4,7,2,0,-5,8,17,5,-10};

int length = 10;

int i;

for(i=0; i<10; i++) {

if(arr[i]%2 == 0) {continue;

}

printf("Odd number is %d\n", arr[i]);

}

scanf("%d", &i);

return 0;

}

Page 23: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 23/31

 

ऊपर    ग example   for loop  use र      array       

number

  

 

 .

अगर number even

 

  

 continue

 use

र 

skip र     और  अगऱ  र for loop   अर    .

  र while loop    continue  use र    .

अ          datatype   र   प         int, char,

float, double etc. य  datatype  format   data store र  .

   अगर    ऱग     store र      char  array   

store र  ऱग,    age store र    int   store र  ऱग. पर  

अगर      य (rectangle)  length और width store र     

  

र  

य 

 2 int variable

य 

और  

 store

र .

 

  

अगर  

 र य   length और width store र    2  variable अऱग  

     प ग. struct  use र  अऱग  अऱग  

variable       र        . struct  use र र  

  य     variable     पग  

  य   length और width store र  program struct  use

य    य    र  ,        better version struct

 use र     ग.#include <stdio.h>

int main() {int length1 = 12;

Page 24: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 24/31

int width1 = 8;

int length2 = 20;

int width2 = 11;

printf("Rectangle1: %d %d\n", length1, width1);

printf("Rectangle2: %d %d\n", length2, width2);

scanf("%d", &length1);

}

ऊपर    ग program        र   . अ      

 struct  use र   ऱ ग     .#include <stdio.h>

struct Rectangle {

int length;

int width;

};

int main() {

struct Rectangle rect1;struct Rectangle rect2;

rect1.length = 12;

rect1.width = 8;

rect2.length = 20;

rect2.width = 11;

printf("Rectangle1: %d %d\n", rect1.length, rect1.width);

printf("Rectangle2: %d %d\n", rect2.length, rect2.width);

scanf("%d", &(rect1.length));

}

 य      र  .  पऱ   struct define

य      Rectangle  और    variable length और  

Page 25: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 25/31

width  . य Rectangle  datatype   यग .   र int   

datatype          य store र       र   य पर  

Rectangle  datatype   यग     int store र       length और width  .     र  य   ऊपर  य.

struct         ऱ      datatype   .   र   

int    datatype    र  य Rectangle    datatype य  

.    {}      variable ऱ      datatype   store

ग.  य Rectangle datatype    variable length और width store

ग. अ    ; ऱग     ऱ अय compile र   error ग .अ Rectangle datatype define   गय   अ     use र   

 .   र    int variable define र     र Rectangle

variable define र  , पर  Rectangle  पऱ struct ऱ  र  .

य Rectangle type    variable rect1 और rect2 define य ग   .

य variable

 value length

और width

ऱ 

  

 

  

  

पऱ 

struct datatype  य define य . अ rect1  length और  

width rect1.length, rect1.width access   .

अ     C   र    

   

    ऱय   और  प    

program ऱ   ऱ   Ready  . अ   pointer   रऱ  र   

 ग  C/C++           .  रऱ  र   प  

र     रग , र              comment

र .

Pointer   पऱ Memory   र     र   ऱ    

Page 26: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 26/31

 Memory Structure    ग. प         ऱग    प  ग  

 computer य     electronic device calculator, micro

processor, mobile phone    0 और 1       ,      detail     .    device  Memory       

    array   र      .          य  गय  

.

1 1 0 1 0 0 0 1 1 0 . . .

Memory ऊपर    गय Array   र       र    

position पर  य   0 store      य 1. र   position    bit

  . 1 bit   य   0 store ग  य 1. Magnetic memory       

bit  magnetic field  direction   र represent य    .

अगर direction clockwise     computer 0 read र  ,

aniclockwise   1. Computer      bit   अ ऱ read य  write  र .    8 bits       प  .  8 bit  1

byte   . ऱ computer Memory      ग      

प  .

11010001 10011101 00101001 11111001 10000011 00100110 . . .

अगर Computer ऊपर    गय memory(array)   पऱ address प 

   ऱग 11010001.   र   र address पर 10011101 etc.

Computer    Memory   पऱ address प    पऱ byte(8

bits) ऱग ,  र address पर   र byte,... अगर  पऱ byte   अर    

र bit प     पऱ  पऱ byte प  पग        

byte  र bit. directly पऱ byte   र bit  प  ,

Page 27: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 27/31

य  पऱ address पग    पऱ byte (पऱ 8 bits) ऱ  ग .

   ऱ  य    Computer   byte level addressing   . र  

byte    address   , पर byte   अर bit  direct address   .

    ऱ     . अगऱ  र    य  ग    Memory    

variable store        pointer  ग. अगऱ  ऱ  प  

पऱ Binary to Decimal Conversion   ऱ और   Binary number   

      ऱ.

अ     C   र            ऱय   और  प    

program ऱ   ऱ   Ready  . अ   pointer   रऱ  र   

 ग  C/C++           .  रऱ  र   प  

र     रग , र              comment

र .

Pointer   पऱ Memory   र     र   ऱ    

 Memory Structure

  

 ग.

प  

  

 

   

 

ऱग  

  

प  

ग  

 computer य     electronic device calculator, micro

processor, mobile phone    0 और 1       ,   

   detail     .    device  Memory       

    array   र      .          य  गय  

.

Page 28: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 28/31

1 1 0 1 0 0 0 1 1 0 . . .

Memory ऊपर    गय Array   र       र    

position पर  य   0 store      य 1. र   position    bit

  . 1 bit   य   0 store ग  य 1. Magnetic memory       

bit  magnetic field  direction   र represent य    .

अगर direction clockwise     computer 0 read र  ,

aniclockwise   1. Computer      bit   अ ऱ read य  

write  र .    8 bits       प  .  8 bit  1byte   . ऱ computer Memory      ग      

प  .

11010001 10011101 00101001 11111001 10000011 00100110 . . .

अगर Computer ऊपर    गय memory(array)   पऱ address प    ऱग 11010001.   र   र address पर 10011101 etc.

Computer    Memory   पऱ address प    पऱ byte(8

bits) ऱग ,  र address पर   र byte,... अगर  पऱ byte   अर    

र bit प     पऱ  पऱ byte प  पग        

byte  र bit. directly पऱ byte   र bit  प  ,

य  पऱ address पग    पऱ byte (पऱ 8 bits) ऱ  ग .

   ऱ  य    Computer   byte level addressing   . र  

byte    address   , पर byte   अर bit  direct address  

 .

    ऱ     . अगऱ  र    य  ग    Memory    

variable store        pointer  ग. अगऱ  ऱ  प  

Page 29: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 29/31

पऱ Binary to Decimal Conversion   ऱ और   Binary number   

      ऱ.

पऱ  र   य     computer   र    1 byte(8 bits) read

र  .    र 1 bit   0 य 1       store      ऱ 1

byte   00000000  ऱर 11111111         य (8 अ    

binary य ) store     . ऱ और  प   00000000 और  

11111111     ऱ     decimal   convert र  प 

 .00000000 = 0 (in decimal)

11111111 = 28

-1 = 255 (in decimal)

ऱ   8 bit य 1 byte   0 255         य store   

  .

  र  अगर    और  य    य store र       2 byte

      ऱर   store र ग. 2 byte   00000000 00000000  11111111 11111111 य 0 65535     य store     .

अ          datatype   र   store य   .

char: ASCII table   य   र    अर (character)      

Decimal य  ऱ   .    char variable     अर store र 

   computer   अर     ऱ  य   store र    .  

  अगर   's' store र        ऱ  य 97(01100001)

store   यग .  table   अ र      अर   store र  

ऱ 255    य    र    ऱ char  store र  

ऱ 1 byte memory   र    .

short int: short int variable 2 byte(16 bits)   store   . 2 byte   0

65535(216

-1)     य store र    .   short int negative

Page 30: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 30/31

value   ऱ    ऱ  य -32768(-215

) 32767(215

-1)    

  ऱ   .

unsigned short int: य   2 byte   ग  ऱ   पर  negative value ऱ   ऱ 0 65535       ऱ   .

int: य 4 byte ऱ   और negative value   ऱ    ऱ -231  

231

-1    value ऱ   .

unsigned int: य   4 byte ऱ   पर   ऱ positive value ऱ 0

232-1    value ऱ   .

float: store र  format complex  य  य  ऱ value

  ऱ   . य 4 byte ऱ  .

double: य 8 byte ऱ   और  ऱ value   ऱ   .

   र      और   datatype      र     अ  

य   .

पऱ  र        computer, memory      byte read

र    . र byte    address     पऱ byte  address

0,  र byte  address 1...   र  .  computer  variable

 value memory     byte पर  ऱ      byte   

address   य  र  . अगर   variable( int)    य byte

ऱ    continuous store र   पऱ byte  address य  र    .    अगर int 101st byte 104th byte  store       

 int  address 101   .

अ  प pointer   र      ऱ ready . अगऱ  र   pointer

  र   प ग.

Page 31: C hindi tutorial

8/7/2019 C hindi tutorial

http://slidepdf.com/reader/full/c-hindi-tutorial 31/31