Posts

while loop

  #include <stdio.h> int main () {     int i = 0 ;     while ( i < 10 )     {         printf ( " %d \n " , i );         i ++;     }     return 0 ; }

type casting

  // typecasting syntax // (type) value #include <stdio.h> int main () {     float a = 10 ;     float b =( float ) 54 / 5 ; //here int & int will give int so we have to convert it to float for float no     printf ( " %d \n " ,( int ) a ); // here i changed the type of the value a     printf ( " %f " , b );     return 0 ; }

switch case

  #include <stdio.h> int main () {     int rank ;     printf ( "enter u r rank in 12 class:" );     scanf ( " %d " ,& rank );     switch ( rank ) // only int and characters are valid here in ( )     {         case 1 : //here "1,2,3" is not counting this is value of variable rank         printf ( "u won car as a gift" );         break ;         case 2 :         printf ( "u won scooty as a gift" );         break ;         case 3 :         printf ( "u won cycle as a gift" );         break ;         default : //this will execute always unless u break the switch         printf ( "this will execute when all cses are false" );     }     return 0 ; }

if else

  #include <stdio.h> int main () {     int age ;     printf ( "enter u r age:" );     scanf ( " %d " ,& age );     printf ( "u r age is %d \n " , age );     if ( age >= 18 )     {         printf ( "u can vote" );     }     else if ( age <= 10 )     {         printf ( "u can vote for kids" );     }         else     {         printf ( "sorry u cannot vote" );     }         return 0 ; }

goto statement

  #include <stdio.h> int main () {     label :         printf ( "hello harish \n " );         goto end ;     goto label ;     end :         printf ( "hi" );         return 0 ; } // goto statement is used to transfer program control to a predefined label

functions4

  // 4. without arguments and without return value #include <stdio.h> char func (); int main () {     int a ;     a = func ();     printf ( " %c " , a );     return 0 ; } char func () {     printf ( "hello world" ); }

functions3

  // 3. without arguments with return value #include <stdio.h> int takenumber (); int main () {     int a ;     a = takenumber ();     printf ( "the number entered is %d " , a );     return 0 ; } int takenumber () {     int i ;     printf ( "enter a number:" );     scanf ( " %d " ,& i );     return i ; }