C Programming Concepts Quiz
16 Questions
1 Views

C Programming Concepts Quiz

Created by
@InviolableRutherfordium

Podcast Beta

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What are the types of operators in C?

The types of operators in C include arithmetic, relational, logical, assignment, increment/decrement, bitwise, conditional, and comma operators.

Write a C program to compute the roots of a quadratic equation given its coefficients?

// C program to compute roots of a quadratic equation
#include 
#include 
int main() {
    float a, b, c, discriminant, root1, root2;
    // code to take input of a, b, and c
    // code to compute discriminant
    // code to compute roots using quadratic formula
    // code to print the roots with appropriate messages
    return 0;
}```

Explain the purpose of a looping statement in C?

The purpose of a looping statement in C is to execute a block of code repeatedly based on a condition.

Write a C program to generate Armstrong numbers between two given limits?

<pre><code class="language-c">// C program to generate Armstrong numbers between given limits #include int main() { int num, originalNum, remainder, result = 0; // code to take input of lower and upper limits // code to iterate through numbers and check for Armstrong property // code to print the Armstrong numbers return 0; }``` </code></pre> Signup and view all the answers

Explain the basic structure of a C program?

<p>The basic structure of a C program includes the preprocessor directive, global declarations, main function, and other functions if required. It also includes comments for better understanding.</p> Signup and view all the answers

Explain the procedure of binary search. Write a C program to perform binary search and explain.

<p>Binary search is a search algorithm that finds the position of a target value within a sorted array. It compares the target value to the middle element of the array and continues narrowing down the search until the value is found or the search space is empty. The C program for binary search should take a sorted array and a target value as input, and return the index of the target value if found.</p> Signup and view all the answers

Write a C program to perform linear search and explain.

<pre><code class="language-c">// C program to perform linear search #include int main() { int arr[] = { /* array elements */ }; int n, key; // code to take input of array elements and key to search // code to iterate through the array and perform linear search // code to print the index if found, else print 'Not found' return 0; }``` </code></pre> Signup and view all the answers

Write a C program to sort 'n' numbers using insertion sort and trace it using the values 65, 25, 12, 22, 13.

<pre><code class="language-c">// C program to sort 'n' numbers using insertion sort #include int main() { int arr[] = {65, 25, 12, 22, 13}; int n = sizeof(arr) / sizeof(arr[0]); // code to perform insertion sort // code to print the sorted array return 0; }``` </code></pre> Signup and view all the answers

Write a C program to sort 'n' numbers using selection sort and trace it using the values 650, 25, 121, 22, 131.

<pre><code class="language-c">// C program to sort 'n' numbers using selection sort #include int main() { int arr[] = {650, 25, 121, 22, 131}; int n = sizeof(arr) / sizeof(arr[0]); // code to perform selection sort // code to print the sorted array return 0; }``` </code></pre> Signup and view all the answers

Classify the function prototypes in C with suitable examples.

<p>Function prototypes in C can be classified as library functions and user-defined functions. Library functions are predefined functions provided by C libraries, while user-defined functions are created by the user. For example, 'int sum(int a, int b);' is a user-defined function prototype, and 'int printf(const char *format, ...);' is a library function prototype.</p> Signup and view all the answers

Write a C program for a Scientific calculator using built-in functions.

<pre><code class="language-c">// C program for a Scientific calculator using built-in functions #include #include int main() { // code to display menu for scientific operations // code to take input of operation and numbers // code to perform the selected operation using built-in functions // code to display the result return 0; }``` </code></pre> Signup and view all the answers

What is a function in C? Explain with a relevant example.

<p>A function in C is a block of code that performs a specific task. It can be called and executed from different parts of the program. For example, 'int sum(int a, int b) { return a + b; }' is a function that takes two integers as input and returns their sum.</p> Signup and view all the answers

Write a C program to implement the sine series using recursion.

<pre><code class="language-c">// C program to implement the sine series using recursion #include #include // function to calculate factorial int factorial(int n) { // code to calculate factorial using recursion } // function to calculate sine series using recursion double sineSeries(double x, int n) { // code to calculate sine series using recursion } int main() { // code to take input of angle in radians and number of terms // code to call the sineSeries function and print the result return 0; }``` </code></pre> Signup and view all the answers

Write a C program for finding the factorial of a number.

<pre><code class="language-c">// C program for finding the factorial of a number #include int main() { int num; int factorial = 1; // code to take input of the number // code to calculate the factorial using a loop // code to print the factorial return 0; }``` </code></pre> Signup and view all the answers

Write a C program for generating the Fibonacci numbers.

<pre><code class="language-c">// C program for generating the Fibonacci numbers #include int main() { int n, first = 0, second = 1, next, c; // code to take input of the number of terms // code to generate and print the Fibonacci series return 0; }``` </code></pre> Signup and view all the answers

Explain linked list and write a C program to implement a linked list.

<p>A linked list is a linear data structure where elements are linked using pointers. Each element points to the next element in the list, forming a chain. The C program to implement a linked list should include the definition of the node structure, functions to perform operations like insertion, deletion, and traversal, and a main function to demonstrate the operations.</p> Signup and view all the answers

More Like This

Use Quizgecko on...
Browser
Browser