Skip to main content

Posts

Showing posts with the label C++

Sum and Difference of Two Numbers Hackerrank Solution - C Language

 Sum and Difference of Two Numbers Hackerrank Solution - C Language  Code: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {      int  a,b;      float  c,d;     scanf( "%d %d %f %f" ,&a,&b,&c,&d);      int  sum1 = a+b;      int  diff1 = a-b;      float  sum2 = c+d;      float  diff2 = c-d;     printf( "%d %d\n" ,sum1,diff1);     printf( "%.1f %.1f" ,sum2,diff2);      return   0 ; }

Conditional Statements in C Hackerrank Solution - C Language

 Conditional Statements in C Hackerrank Solution - C Language Code: #include   < assert.h > #include   < limits.h > #include   < math.h > #include   < stdbool.h > #include   < stddef.h > #include   < stdint.h > #include   < stdio.h > #include   < stdlib.h > #include   < string.h > char * readline(); int  main() {      char * n_endptr;      char * n_str = readline();      int  n = strtol(n_str, &n_endptr,  10 );      if  (n_endptr == n_str || *n_endptr !=  ' \ 0 ' ) { exit(EXIT_FAILURE); }      // Write Your Code Here      if (n== 1 ){         printf( "one" );     } else   if (n== 2 ){         printf( "two" );     } else   if (n== 3 ){         printf( "three" );     } else   if (n== 4 ){         printf( "four" );     } else   if (n== 5 ){         printf( "five" );     } else   if (n== 6 ){         printf( "six" );     } else   if (n== 7 ){         printf( "s

1D Arrays in C Hackerrank Solution - C Language

  1D Arrays in C Hackerrank Solution - C Language  Code : #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {      int  n;     scanf( "%d" ,&n);      int  arr[n];      int  sum =  0 ;      for ( int  i= 0 ;i<n;i++){         scanf( "%d" ,&arr[i]);         sum = sum + arr[i];     }       printf( "%d" ,sum);      return   0 ; }

For Loop in C Hackerrank Solution - C Language

 For Loop in C Hackerrank Solution - C Language Code: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main()  {      int  a, b;     scanf( "%d\n%d" , &a, &b);      for ( int  i=a;i<=b;i++){       if (i>= 1  && i<= 9 ){           if (i== 1 ){              printf( "one\n" );          } else   if (i== 2 ){              printf( "two\n" );          } else   if (i== 3 ){              printf( "three\n" );          } else   if (i== 4 ){              printf( "four\n" );          } else   if (i== 5 ){              printf( "five\n" );          } else   if (i== 6 ){              printf( "six\n" );          } else   if (i== 7 ){              printf( "seven\n" );          } else   if (i== 8 ){              printf( "eight\n" );          } else   if (i== 9 ){              printf( "nine\n" );          }    

Sum of Digits of a Five Digit Number Hackerrank Solution - C

 Sum of Digits of a Five Digit Number Hackerrank Solution - C Code : #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {           int  n;     scanf( "%d" , &n);      //Complete the code to calculate the sum of the five digits on n.      int  sum =  0 ;      while (n!= 0 ){          int  r = n% 10 ;         n = n/ 10 ;         sum = sum + r;     }     printf( "%d" ,sum);      return   0 ; }

Functions in C Hackerrank Solution - C Language

 Functions in C Hackerrank Solution - C Language For Explanation Watch Video : Code: #include   < stdio.h > /* Add `int max_of_four(int a, int b, int c, int d)` here. */ int  max_of_four( int  a,  int  b,  int  c,  int  d){      if (a>=b && a>=c && a>=d){          return  a;     } else   if (b>=a && b>=c && b>=d){          return  b;     } else   if (c>=a && c>=b && c>=d){          return  c;     } else {          return  d; //6     } } int  main() {      int  a, b, c, d;     scanf( "%d %d %d %d" , &a, &b, &c, &d);      int  ans = max_of_four(a, b, c, d);     printf( "%d" , ans);           return   0 ; }

Hackerrank hello world solution in c

Hackerrank hello world solution in c Watch Video: Code:: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main()  {           char  s[ 100 ];     scanf( "%[^\n]%*c" , &s);           /* Enter your code here. Read input from STDIN. Print output to STDOUT */        printf( "Hello, World!\n" );     printf( "%s" ,s);           return   0 ; }