Featured Post

Variable Sized Arrays Discussions | C++ | HackerRank Variable Length Arrays in C and C++ - GeeksforGeeks

Variable Sized Arrays Variable Sized Arrays Discussions | C++ | HackerRank Consider an  -element array,  , where each index   in the array c...

Monday, March 22, 2021

HackerRank solution for Functions In C++ - Programming With

HackerRank solution for Functions In C++ - Programming With   

Functions  

Functions are a bunch of statements glued together. 

A function is provided with zero or more arguments, and it executes the statements on it. 

Based on the return type, it either returns nothing (void) or something.

 A sample syntax for a function is return_type function_name(arg_type_1 arg_1, arg_type_2 arg_2, ...) { ... ... ... [if return_type is non void] return something of type `return_type`; }

 For example, a function to read four variables and return the sum of them can be written as 

int sum_of_four(int a, int b, int c, int d) 

int sum = 0; 

sum += a;

 sum += b;

 sum += c; 

sum += d; 

return sum;

 } 

You have to write a function

 int max_of_four(int a, int b, int c, int d)

 which reads four arguments and returns the greatest of them. 

Input Format


 Input will contain four integers - , one in each line.


 Output Format 

Print the greatest of the four integers. 

PS: I/O will be automatically handled. 


Sample Input 3 4 6 5 


Sample Output 6






#include <iostream>
#include <cstdio>
using namespace std;

/*
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;
}


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;
}





Sunday, March 21, 2021

For Loop Discussions | C++ | HackerRank HackerRank/for-loop.cpp at master

 For Loop  HackerRank Solution

A for loop is a programming language statement which allows code to be repeatedly executed. 


The syntax for this is for ( ; ; ) expression_1 is used for intializing variables which are generally used for controlling terminating flag for the loop. 


expression_2 is used to check for the terminating condition. 


If this evaluates to false, then the loop is terminated. expression_3 is generally used to update the flags/variables.


 A sample loop will be for(int i = 0; i < 10; i++) { ... } Input Format You will be given two positive integers, and ( ), separated by a newline.


 Output Format For each integer in the interval : If , then print the English representation of it in lowercase. 
That is "one" for , "two" for , and so on.


 Else if and it is an even numeber, then print "even".
 Else if and it is an odd number, then print "odd".

Note: Sample Input


 8 11

 Sample Output


 eight nine even odd





For Loop C++ Code


#include <iostream>
#include <cstdio>
using namespace std;

int main() 
{
    // Complete the code.
     int a,b; 
     cin>>a>>b;
     for(int n=a;n<=b;n++)
     {
        if(n<= 9||n==1 )
        {
            if(n==1)
            {
                cout<<"one"<<endl;
            }
            else if(n==2)
            {
                cout<<"two"<<endl;
            }
            else if(n==3)
            {
                cout<<"three"<<endl;
            }
            else if(n==4)
            {
                cout<<"four"<<endl;
            }
            else if(n==5)
            {
                cout<<"five"<<endl;
            }
            else if(n==6)
            {
                cout<<"six"<<endl;
            }
            else if(n==7)
            {
                cout<<"seven"<<endl;
            }
            else if(n==8)
            {
                cout<<"eight"<<endl;
            }
            else if(n==9)
            {
                cout<<"nine"<<endl;
            }
        }
        else if(n>9)
                {
                    if(n%2==0)
                    cout<<"even"<<endl;
                    else {
                    cout<<"odd"<<endl;
                         }
                }
        
        
    }
 

    
    
        return 0;
}





follow Me on Linkedin

"Hello World!" in C Discussions | C | HackerRank Solution by Sintu Kumar suman

 "Hello World!" in C  



This is a hacker rank Problem the only question has been copied from hacker rank 
Answer is given by me.

"Hello World!" in C Objective In this challenge,
 we will learn some basic concepts of C that will get you started with the language. 

You will need to use the same syntax to read input and write output in many C challenges. 

Task This challenge requires you to print on a single line, and then print the already provided input string to stdout.

 Note: You do not need to read any input in this challenge. Input Format You do not need to read any input in this challenge. 

Output Format Print on the first line, and the string from the given input on the second line.


 
Sample Input 0 

Welcome to C programming. 



Sample Output 0 

Hello, World! 
Welcome to C programming.












#include <stdio.h>
#include <string.h>

int main() 
{
 
    char s[100];
    scanf("%[^\n]%*c", &s);
    printf("Hello, World!\n");
    printf(s);
 
    return 0;
}






Follow me on Linkedin



https://www.linkedin.com/in/sintu-kumar-suman-2a49b817b/

Sintu Kumar Suman
Software Developer