Server Side Programming Articles - Page 2270 of 2650

How to check if input is numeric in C++?

Nishu Kumari
Updated on 30-May-2025 18:07:17

6K+ Views

Numeric input means a value that contains only digits from 0 to 9, without any letters or special characters. In this article, we'll show you how to write a C++ program to check whether the input is numeric. Let's understand this with a few examples: //Example 1: Input: 12345 Output: Valid numeric input //Example 2: Input: 12a5 Output: Not a numeric input We will cover two common ways to check if the input is numeric or not in C++. Using std::getline with std::isdigit Check Using stringstream to Parse ... Read More

How to find the size of an int[] in C/C++?

Nishu Kumari
Updated on 30-May-2025 18:05:34

8K+ Views

In C and C++, arrays can store multiple values of the same data type. This problem is about finding how many elements are present in a statically declared int[] array (not pointers or dynamically allocated arrays). We'll learn how to find the size of an int[] in both C and C++. Let's understand this with an example: //Example 1 input: int numbers[] = {10, 20, 30, 40, 50}; This array has 5 elements. Output: Number of elements: 5 //Example 2: Input: int values[] = {1, 2, 3}; This array has 3 elements. Output: Number of elements: 3 ... Read More

How to implement a copy constructors in C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

538 Views

Here we will see how the copy constructors are implemented in C++. Before discussing that we should know what is the copy constructor.The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to −Initialize one object from another of the same type.Copy an object to pass it as an argument to a function.Copy an object to return it from a function.If a copy constructor is not defined in a class, the compiler itself defines one. If the class has pointer ... Read More

Print a number 100 times without using loop, recursion and macro expansion in C

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

571 Views

In this section we will see how to print a number 100 times in C. There are some constraints. We cannot use loops, recursions or macro expansions.To solve this problem we will use the setjump and longjump in C. The setjump() and longjump() is located at setjmp.h library. The syntax of these two functions are like below.Example#include #include jmp_buf buf; main() {    int x = 1;    setjmp(buf); //set the jump position using buf    printf("5"); // Prints a number    x++;    if (x

Program to display hostname and IP address C

Smita Kapse
Updated on 30-Jul-2019 22:30:26

565 Views

In this section we will see how to see the Host name and IP address of the local system in an easier way. We will write a C program to find the host name and IP.Some of the following functions are used. These functions have a different task. Let us see the functions and their tasks.FunctionDescriptiongethostname()It finds the standard host name for the local computer.gethostbyname()It finds the host information corresponding to a host name from host databaseiten_ntoa()It converts an IPv4 Internet network address into an ASCII string into dotted decimal format.Example#include #include #include #include #include ... Read More

Modulus of two float or double numbers using C

Anvi Jain
Updated on 30-Jul-2019 22:30:26

8K+ Views

Here we will see how to get the modulus of two floating or double type data in C. The modulus is basically finding the remainder. For this, we can use the remainder() function in C. The remainder() function is used to compute the floating point remainder of numerator/denominator.So the remainder(x, y) will be like below.remainder(x, y) = x – rquote * yThe rquote is the value of x/y. This is rounded towards the nearest integral value. This function takes two arguments of type double, float, long double, and returns the remainder of the same type, that was given as argument. ... Read More

trunc() , truncf() , truncl() in C language

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

2K+ Views

Here we will see three functions. These functions are trunc(), truncf() and the truncl(). These functions are used to convert floating point values into truncated form.The trunc() FunctionThis function is used to truncate double type value. And return only the integer part. The syntax is like below.double trunc(double argument)Example#include #include main() {    double a, b, x, y;    x = 53.26;    y = 75.86;    a = trunc(x);    b = trunc(y);    printf("The value of a: %lf", a);    printf("The value of a: %lf", b); }OutputThe value of a: 53.000000 The value of a: 75.000000The ... Read More

setjump() and longjump() in C

Smita Kapse
Updated on 30-Jul-2019 22:30:26

3K+ Views

In this section, we will see what are the setjump and longjump in C. The setjump() and longjump() is located at setjmp.h library. The syntax of these two functions is like below.setjump(jmp_buf buf) : uses buf to store current position and returns 0. longjump(jmp_buf buf, i) : Go back to place pointed by buf and return i.These are used in C for exception handling. The setjump() can be used as try block, and longjump() can be used as throw statement. The longjump() transfers control the pointe which is pointed by setjump().Here we will see how to print a number 100 ... Read More

How to measure time taken by a function in C?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

15K+ Views

Here we will see how to calculate the time taken by the process. For this problem, we will use the clock() function. The clock() is present in the time.h header file.To get the elapsed time, we can get the time using clock() at the beginning, and at the end of the tasks, then subtract the values to get the differences. After that, we will divide the difference by CLOCK_PER_SEC (Number of clock ticks per second) to get the processor time.Example#include #include void take_enter() {    printf("Press enter to stop the counter ");    while(1) {       ... Read More

How to change the output of printf() in main()?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

340 Views

Here we will see how to change the output of the printf() function from main(). Here we will define a function that will change all of the printf() statements with the given type to another type.We will use the #define macro to do this task. This macro will be defined inside the function. We can directly put the #define line without using it in the function, but in that case always the printf() will be changed. To control it using main, we have to call the function first.Example#include void changePrintf() { //always any printf will print 50    #define ... Read More

Advertisements