Posts

Showing posts from October, 2020

UNION

 UNION  INPUT #include   <stdio.h> #include   <string.h>   union   student {       int   id ;      int   marks ;      char   fav_char ; } ; int   main () {      union   student   Harry ,  Shubham ,  Ravi ;      Harry . id  =  67 ;      Shubham . id  =  7 ;      Ravi . id  =  6 ;      Harry . marks  =  189000000 ;      Shubham . marks  =  9 ;      Ravi . marks  =  0 ;      Harry . fav_char  =  'f' ;      Shubham . fav_char  =  'e' ;      Ravi . fav_char  =  'p' ;      printf ( " \n Harry got %d marks. \n " ,  Harry...

TYPEDEF

TYPEDEF  INPUT #include   <stdio.h> #include   <string.h> typedef    struct   student {       int   id ;      int   marks ;      char   fav_char ; }  std ; int   main () {      std   Harry ,  Shubham ,  Ravi ;      Harry . id  =  67 ;      Shubham . id  =  7 ;      Ravi . id  =  6 ;      Harry . marks  =  189000000 ;      Shubham . marks  =  9 ;      Ravi . marks  =  0 ;      Harry . fav_char  =  'f' ;      Shubham . fav_char  =  'e' ;      Ravi . fav_char  =  'p' ;      printf ( " \n Harry got %d marks. \n " ,  Harry ...

STRUCTURES IN C

 STRUCTURES IN C  INPUT #include   <stdio.h> #include   <string.h> struct   student {       int   id ;      int   marks ;      char   fav_char ; }; int   main () {      struct   student   Harry ,  Shubham ,  Ravi ;      Harry . id  =  67 ;      Shubham . id  =  7 ;      Ravi . id  =  6 ;      Harry . marks  =  79 ;      Shubham . marks  =  9 ;      Ravi . marks  =  7 ;      Harry . fav_char  =  'f' ;      Shubham . fav_char  =  'e' ;      Ravi . fav_char  =  'p' ;      printf ( " \n Harry got %d marks. \n " ,  Harry . marks...

ARRAY REVERSAL

  ARRAY REVERSAL INPUT #include   <stdio.h> void   arrayrev ( int   arr [] ) {      int   temp ;      for  ( int   i  =  0 ;  i  <  3 ;  i ++)     {          temp  =  arr [ i ];          arr [ i ] =  arr [ 6  -  i ];          arr [ 6  -  i ] =  temp ;     } } int   main () {      int   arr []  = { 2 ,  3 ,  4 ,  44 ,  5 ,  6 ,  7 ,  8 };      printf ( "Before reversal of array \n " );      for  ( int   i  =  0 ;  i  <  7 ;  i ++)     {        ...

STRINGS IN C

 STRINGS IN C  INPUT #include   <stdio.h> void   printstr ( char   string [] ) {      int   i = 0 ;      while  ( string [ i ]|= ' \0 ' )     {          printf ( "%c" , string [ i ]);          i ++;     }      } int   main () {      char   str [ 6 ]= "harry" ;      //char str[]={'h','a','r','r','y','\0'};      printstr ( str );      return   0 ; } OUTPUT harry INPUT gets ( str ); printf ( "Print the string %s" ,  str ); OUTPUT Nandini is a good girl. Print the string Nandini is a good girl.  

PRINT STAR

 PRINT STAR  INPUT #include   <stdio.h> int   starpattern ( int   rows ) {      for  ( int   i  =  0 ;  i  <  rows ;  i ++)     {          printf ( " \n " );          for  ( int   j  =  0 ;  j  <=  i ;  j ++)         {              printf ( "* " );         }     } } int   reversestarpattern ( int   rows ) {      for  ( int   i  =  rows ;  i  >=  1 ;  i --)     {          for  ( int   j  =  0 ;  j  <  i ;  j ++)  ...

POINTERS

 POINTERS  INPUT #include   <stdio.h> int   main () {      int   a  =  23 ;      int  * ptra  = & a ; int  * ptrB  =  NULL ;      printf ( "The address of the pointer is %x \n  " , & ptra );      printf ( "The address of the a is %x \n  " , & a );      printf ( "The value of the a is %d \n  " , * ptra );      printf ( "The value of the a is %d \n  " ,  a );  printf ( "The value of the POINTER TO B is %p \n  " ,  ptrB );      return   0 ; } OUTPUT The address of the pointer is 61ff18 The address of the a is 61ff1c The value of the a is 23 The...

FIBONACCI SERIES FROM ITERATIVE APPROACH

  FIBONACCI SERIES FROM ITERATIVE APPROACH INPUT #include   <stdio.h> int   main () {      int   a  =  0 ;      int   b  =  1 ;      int   n ;   printf ( "Enter the no. of series \n " );          scanf ( "%d" , & n );      for  ( int   i  =  0 ;  i  <  n ;  i ++)     {         printf ( "%d \n " , a );          b  =  a  +  b ;          a  =  b  -  a ;     }      return   0 ; } OUTPUT Enter the no. of series 5 0 1 1 2 3

FIBONACCI SERIES USING RECURSION

FIBONACCI SERIES USING RECURSION  INPUT #include   <stdio.h> int   fib ( int ); int   main () {      int   n ,  i = 0 ,  f ;      printf ( "Enter te number of terms you want in the series \n " );      scanf ( "%d" , & n );      for  ( f  =  1 ;  f  <=  n ;  f ++)     {                   printf ( "%d \n " ,  fib ( i ));          i ++;     }      return   0 ; } int   fib ( int   n ) {      if  ( n  ==  0  ||  n  ==  1 )     {          return   n ;    ...

ARRAYS

  ARRAYS INPUT #include   <stdio.h> int   main () {      int   marks [ 6 ];      marks [ 1 ]= 234 ;      marks [ 2 ]= 23 ;      marks [ 3 ]= 24 ;      marks [ 4 ]= 34 ;      marks [ 5 ]= 2 ;      for  ( int   i  =  1 ;  i  <  6 ;  i ++)     {          printf ( "The marks of student %d are %d \n " , i , marks [ i ]);     }            return   0 ; } OUTPUT The marks of student 1 are 234 The marks of student 2 are 23 The marks of student 3 are 24 The marks of student 4 are 34 The marks of student 5 are 2  

UNIT CONVERSION PROGRAM

UNIT CONVERSION PROGRAM INPUT #include   <stdio.h> float   kgtomiles ( float   number ) {      return  ( number  *  0.62 ); } float   inchestofoot ( float   number ) {      return  ( number  *  0.083 ); } float   cmtoinches ( float   number ) {      return  ( number  *  0.39 ); } float   poundtokgs ( float   number ) {      return  ( number  *  0.45 ); } float   inchestometers ( float   number ) {      return  ( number  *  0.02 ); } int   main () {      int   conversion ;      float   num ;      char   type ;      printf ( "Enter \n  1 if you want to convert kg to miles \n  2 if you want ...