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.
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
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.
4. Write a C program to convert a string to a double. Go to the editor
Expected Output :
Output= 4.00
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!
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
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
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
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
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.
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
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.
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.
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
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.
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
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
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
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
Static variable inside of a function in C
The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().
The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.
The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().
Ref : https://bit.ly/3fOq7XP
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework