In: Computer Science
C PROGRAMMING
1. Write a C Language inline function that computes the cube of float X, if X is greater than 1 and X is less than 100. Put the inline function in a main program that reads X from the keyboard, calls the function, and then outputs the result.
2. Show an empty statement and detail what it does?
3. A collection of predefined functions is called a
4. T___ F___ A function should be created if the code will be used often in the program or in future programming.
#include <stdio.h>
inline float cube(float x){
return x*x*x;
}
int main() {
float a;
float result;
printf("Enter the value..\n");
scanf("%f",&a);
printf("Entered value is: %f\n",a);
if(a>1 && a<100){
result = cube(a);
printf("Cube result: %f\n",result);
}
else{
printf("The entered value should be greater than 1 and less than 100! Try again!");
}
return 0;
}
#include <stdio.h>
int main() {
char text[25] = "Miracle can happen";
int i;
for(i = 0; text[i] != 'q'; i++)
;//empty statement
//If we have 'q' in our string it will not go inside the loop
return 0;
}
//When we want to find the index of first occurrence of a given character in a string in our case its q.
#include <stdio.h>
int main() {
for(;;;) //empty loop it will run forever.
}
3. A collection of predefined functions is called a Library.
As the C in-built functions are collected and placed together in a library every library does a specific task.
for example stdio.h takes case of input output tasks.
database is not the answer as no predifined database s their in C.
Subroutine is kind-of a function which user creates with specific instructions associated with a name.
Directives are the initial lines of program begain with # it is to include some library etc.
4. A function should be created if the code will be used often in the program or in future programming - TRUE
because when we need some lines of code to run often then without writing the same code again and again we write it separately as a function and we call that function whenever we want to run those specific codes.