# C Programming Exercises, Practice, Solution : Variable Type

## C Variable Type [18 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

1. Write a C program which will invoke the command processor to execute a command. Go to the editor

Expected Output :

```Is command processor available?
Command processor available!
Executing command DIR
00c40280-5e27-11e6-bd4f-71e8825f8ea3
01691610-41e1-11e6-901d-35b72ececc72
...........
ff827330-443a-11e6-9820-23e2f60d924e
file.txt
logging_example.out
test.txt
Returned value is: 0.
```

Click me to see the solution

2. Write a C program to convert a string to an unsigned long integer. Go to the editor

Test Data and Expected Output :

```Input an unsigned number: 25
Output: 25
```

Click me to see the solution

3. Write a C program to convert a string to a long integer. Go to the editor

Expected Output :

```In decimals: 2016, 4235440, -3624422, 5947391.
```

Click me to see the solution

4. Write a C program to convert a string to a double. Go to the editor

Expected Output :

```Output= 4.00
```

Click me to see the solution

5. Write a C program to generate a random number. Go to the editor

Test Data and Expected Output :

```Guess the number (1 to 10): 6
The number is higher

Guess the number (1 to 10): 7
That is correct!
```

Click me to see the solution

6. Write a C program to sort the elements of an array. Go to the editor

Test Data and Expected Output :

```Input the number of elements to be stored in the array :5
Input 6 elements in the array :
element - 0 : 15
element - 1 : 26
element - 2 : 42
element - 3 : 82
element - 4 : 35

After sorting the array are :
15
26
35
42
82
```

Click me to see the solution

7. Write a C program to integral quotient and remainder of a division. Go to the editor

Test Data and Expected Output :

```Input numerator : 2500
Input denominator : 235
quotient =  10, remainder = 150
```

Click me to see the solution

8. Write a C program to return the absolute value of a long integer. Go to the editor

Test Data and Expected Output :

```Input 1st number (positive or negative) : 25
Input 2nd number (positive or negative) : -125
The absolute value of 1st number is : 25
The absolute value of 2nd number is : 125
```

Click me to see the solution

9. Write a C program to get the environment string. Go to the editor

Expected Output :

```The set path is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin
:/bin:/usr/games:/usr/local/games
```

Click me to see the solution

10. Write a C program to return the quotient and remainder of a division. Go to the editor

Test Data and Expected Output :

```Input numerator : 2000
Input denominator : 235
quotient =  8, remainder = 120.
```

Click me to see the solution

11. Write a C program to allocate a block of memory for an array. Go to the editor

Test Data and Expected Output :

```Input the number of elements to be stored in the array :5
Input 5 elements in the array :
element 1 : 25
element 2 : 30
element 3 : 35
element 4 : 20
element 5 : 40
Values entered in the array are :
25  30  35  20  40
```

Click me to see the solution

12. Write a C program to perform a binary search in an array. Go to the editor

Test Data and Expected Output :

```Input the number of elements to be stored in the array :5
Input 5 elements in the array :
element - 1 : 25
element - 2 : 20
element - 3 : 18
element - 4 : 13
element - 5 : 15
Input a value to search : 18
18 is found in the array.
```

Click me to see the solution

13. Write a C program to convert a string to an integer. Go to the editor

Test Data and Expected Output :

```Input a number : 1972
The value Input is 1972.```

Click me to see the solution

14. Write a C program to convert a string to a double. Go to the editor

Test Data and Expected Output :

```Input a number : 25
The original number is : 25.000000
After division by 2 the number is : 12.500000
```

Click me to see the solution

15. Write a C program to set a function that will be executed on termination of a program. Go to the editor

Expected Output :

```This is the message from main function.
Here is the message returning from newFunctionTwo.
Here is the message returning from newFunctionOne.```

Click me to see the solution

16. Write a C program to return the absolute value of an integer. Go to the editor

Test Data and Expected Output :

```Input a positive or negative number :-25
The absolute value of the given number is : 25```

Click me to see the solution

17. Write a C program to abort the current process. Go to the editor

Expected Output :

``` File does not exist or error, in opening the file.
timeout: the monitored command dumped core
Aborted
```

Click me to see the solution

18. Write a C program to demonstrate the working of keyword long. Go to the editor

Expected Output :

``` The size of int = 4 bytes
The size of long = 8 bytes
The size of long long = 8 bytes
The size of double = 8 bytes
The size of long double = 16 byte
```

Click me to see the solution

C Programming Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

﻿

## C Programming: Tips of the Day

Placement of the asterisk in pointer declarations:

4, 5, and 6 are the same thing, only test is a pointer. If you want two pointers, you should use:

```int *test, *test2;
Or, even better (to make everything clear):
int* test;
int* test2;
```

Ref : https://bit.ly/2Zm0HMO