C Programming - Unit Wise Questions

Questions Organized by Units
Unit 1: Problem Solving with Computer
35 Questions

1. Draw a flow chart and write an algorithm to find out whether a given number is zero or +ve or -ve.

6 marks
Details
Official Answer

Algorithm:

1.      Start

2.      Print”Enter a number”.

3.      Read n.

4.      If n>0 then print “The number is positive”

Else if n<0 print “The number is negative”

Else “The number is zero”.

5.      Stop

 Flowchart:


AI Generated Answer

AI is thinking...

1. What is logical error? Write flowchart and program for checking whether the number entered by the user is exactly divisible by 5 or by 11. [1+5]

OR

What is algorithm? Write an algorithm to check given number is prime or composite. [1+5]

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. Draw the flowchart for the solution of a quadratic equation and write an algorithm and explain it.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. Discuss structure of a C Program with suitable example.
10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. Write an algorithm and flow chart to determine whether a given integer is odd or even and explain it.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1) Write an algorithm and flowchart to find out whether a given integer is zero, +ve or –ve and explain it.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. Explain the structure of C-Program with example.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. Draw a flow chart and write an algorithm to find a number is divisible by either 5 or 7? (6)

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. Why flow chart is required? Explain different symbols used in the flow chart and explain with suitable example.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. What do you mean by looping? Explain while loop with suitable example. Compare while loop with do while loop. Write a program to find sum and average of first n natural numbers.[1+3+2+4]

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

2. What are the benefits of using arrays? Compare one dimensional array with two dimensional array. Write a program to find transpose of a matrix.[2+2+6]

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

1. Define function and list its advantages. Describe the difference between passing arguments by value and passing arguments by address with suitable program.[4 + 6]

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3. What is structure? How is it different from union? Create a structure named course with name,code and credit_hour as its member. Write a program using this structure using this structure to read data of 5courses and display data of those courses with credit_hour grater than 3.[1+2+7]

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

2. Explain how structure is different from union? Make a program using structure of booklist having data member's title, author, and cost. Enter four data and calculate total cost.[3 + 4 + 3] 

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4. What is algorithm? How is it different from flow chart?

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3. Explain various modes in which file can be opened? Write a program to CREATE and WRITE N numbers in a file "NUMBER.TXT" . Open this file then read its content and put all even numbers in one file "EVEN.TXT" and odd numbers in another file"ODD.TXT". [2+4+4]

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4. Explain flowchart with example. What are the benefits of using flowchart?[3+2]

5 marks
Details
Official Answer

Answered by Puja Lakhe.CSIT 1st sem,BMC


AI Generated Answer

AI is thinking...

5. What is data type? Why do we need it in programming? Explain any three basic data types with example.(1+1+3) 

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4. What do you mean by a problem analysis? What are the properties of a good algorithm? Explain the Compilation and Execution of any C program?[1+1+3]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

8. What is preprocessor directive? Discuss # define directive with example. 

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

6. What do you mean by unformatted I/O? Explain.[5]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

7. Write a program to display first in prime numbers.[5]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

5. Define nested if else statement with suitable flowchart. Write a C code to check if user given input is exactly divisible by 5 or 11 using nested if else statement?[2+3]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

6. List various binary and unary operators used in C? Write a program that uses "while"loop to compute and prints the sum of a given numbers of squares. For example, if 4 is input, then the program will print 30, which is equal to 12+22+32+42 [1+4]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

8. Write a program to find product of two integers using your own function.[5]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

7. "Size of character array is always declared one more that the input size." Justify the statement. Write a program to read a character array in input as "TRIBHUVAN UNIVERSITY" from the user and find out how many times a character "I" occurs in that array?[1+4]

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

9. Define pointer. How do you return pointers from functions? Explain with example.[1+4]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

10. Explain different file  I/O functions with example.[5]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

8. Write syntax to declare and initialize 2-dimensional array? With suitable program logic explain how would u find transpose of a 3*3 matrix.[1+4]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

11. Write a program to draw a circle using graphics function.[5]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

9. Explain the concept of recursive function using the example program to find the factorial of given positive integer.[5]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

12. Write short notes on:[2x2.5=5]

a. Compilation and execution

b. Operator precedence and associativity

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

10. Describe the fundamental concept of pointer and its arithmetic with suitable examples.[5]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

11. Explain the use of graphical functions. Write a program to draw a triangle using line() graphics function.[1+4]

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

12. Write short notes on:[2+3]

i) Dynamic Memory Allocation

ii) break and continue

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

Unit 2: Elements of C
8 Questions

2. How can you declare the variable in C? Explain with example.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

2) What are the basic four data types used in C programming? What are its size and range? Explain.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

2. Find the value of “a” in each of the following statements:

Int i = 2, j = 5, k = 7

Float a = 1.5, b = 2.5, c = 3.5

(a) a = c – i / j + c / k;

(b) a = (c – i) / k + (j + b) / j;

(c) a = b * b – ((i+j) / c);

(d) a = b – k + j / k + i * c;

(e) a = c + k % 2 + b;

(f) a = (b + 4) % (c + 2);

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

2. What do u mean by statement? Expalin the different types of statement with example.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3. Find the error in the given program and explain it. Write the correct program.

#include<stdio.h>

include<math.h>

main

{

float p, r, n;

printf(“Please enter a value for the principle (P):”);

scanf(“%f”, &p);

printf(“Please enter a value for the interest rate (R)”);

scanf(“%f”, &r);

printf(“Please enter a value for the number of years (n):”):

scanf(“%f”, n);

f = p * pow + r/100),n);

printf(\\n The final value (F) is: %. 2f\\n”, f);

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3. A machine is purchased which will produce earning of Rs. 20000 per year while it lasts. The machine costs Rs. 120000 and will have a salvage value of Rs. 20000 when it is condemned. If the 12 percent per annum can be earned on alternative investments, what should be the minimum life of the machine to make it a more attractive investment compared to alternative investments?

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3. Describe the four basic data types with example.

6 marks
Details
Official Answer

 Data type in C refers to an extensive system used for declaring variable for function of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.

The Four basic data types are described below:

1.      Integer type (int):

  •      Integers are whole numbers.
  •      It requires 16 bit of storage i.e. 2 bytes.
  •      Three classes of integer: Integer(int)Short integer (short int) and Long integer (long int)


E.g. int a;    int x=5;

 

2. Floating point type (float):

  • Floating point type are fractional numbers.
  • A variable of float type requires 4 bytes and the range of values that can be stored in it, is 3.4e-38 to 3.4e+38.\\
  • Variable is defined as:

float a;

float x=23.7;

 

3. Character type (char):

  •      All single character used in programs belong to character type.
  •      The character data type holds exactly 8 bits (1 byte).
  •      The unsigned char has values between 0 and 255.
  •      The signed char has values from -128 to 127.
  •      Variable is declared as:

char var1= ‘h’;

            Here, var1 is a variable of type char which is storing a character ‘h’.

 

4. Double precision floating point type (double):

     i. Double precision:

  •          It reserves 8 bytes in memory.
  •          It represents fractional number of the range 1.7e-308 to 3.4e+308

   ii. Long double precision:

  •          It reserves 10 bytes in memory.
  •          It represents fractional numbers of the range 3.4e-4932 to 1.1e+4932
AI Generated Answer

AI is thinking...

5. What is type conversion? Discuss type casting with suitable example.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

Unit 3: Input and Output
2 Questions

7. Write a program that computes the sum of digits of a given integer number. 

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

10) What are the three types of input/output functions which support in C-programming? Explain with example.

OR

Write short notes on:

a.) Delimiters                             b.) Graphics function

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

Unit 4: Operators and Expression
6 Questions

2. What are the different types of operators available in C?Explain.

6 marks
Details
Official Answer

An operator is a symbol that operates on single or multiple data items. It is used in program to perform certain mathematical or logical manipulations. E.g. In a simple expression 2+3, the symbol “+” is called an operator which operates on two data items 2 and 3.

C operators can be classified into following types:

1. Arithmetic Operators

Arithmetic operators are used to perform arithmetic operations. There are five arithmetic operators:


2. Relational Operators

- Relational operators are used to compare two operands and taking decisions based on their relation.

-  Result of relational expression is either True(1) or False(0).

-  Relational operators are used in decision making and loops.

-  Relational operators are:


3. Logical Operators

- Logical operators are used to compare logical and relational expression.

- The operands of logical operators must be either Boolean value (1 or 0) or expression that produces Boolean value.

-  The output of these operators is always 0 (flase) or 1 (true).

The logical operators are:  


4. Assignment Operator

-  Assignment operators are used to assign the result of an expression to a variable.

-  The mostly used assignment operator is ‘=’. 

-   C also supports shorthand assignment operators which simplify operation with assignment.


5. Increment and Decrement Operators

- Increment operator is used to increase the value of an operand by 1.

- Decrement operator is used to decrease the value of an operand by 1.  


6. Conditional Operator (Ternary Operator)

-  It takes three arguments.

- Conditional operators return one value if condition is true and returns another value if condition is false.

Syntax: (condition) ? value_if_true : value_if_false


etc.

AI Generated Answer

AI is thinking...

2. What is operator? List any six operators used in C-programming language. Write a program to find least number between any two numbers using ternary operator. [1+2+3]

6 marks
Details
Official Answer

An operator is a symbol that operates on single or multiple data items. It is used in program to perform certain mathematical or logical manipulations.

E.g. In a simple expression 2+3, the symbol “+” is called an operator which operates on two data items 2 and 3.

C operators can be classified into following types:

  • Arithmetic Operators
  • Relational Operators
  • Logical Operators
  • Assignment Operators
  • Increment and Decrement Operators
  • Conditional Operators

Program to find least number between any two numbers using ternary operator:

#include <stdio.h>

#include<conio.h>

int main()

{

    int n1, n2,least; 

    printf("Enter two numbers: ");

    scanf("%d%d", &n1, &n2);

    least = n1<n2 ? n1:n2;

    printf("The least number is %d",least);

    getch();

    return 0;

}

AI Generated Answer

AI is thinking...

2.Discuss logical operators along with the truth table. Write a program using switch statement to display EXCELLENT, VERY GOOD, GOOD, SATISFACTORY, or F AIL if the user enters A, B, C,D,E respectively. (3+3)

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3. Explain the relational operator and Increment/decrement operator with example.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4. Discuss different logical operators in detail.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

6. Discuss increment and decrement operators with example.

5 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

Unit 5: Control Statement
15 Questions

1. What is looping statement? Discuss different looping statements with suitable example of each. (2+8)

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

2. Discuss different types of if statements with example of each. Differentiate if statement with switch statement.

10 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3) Explain the “if.......else” statement with example.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

3. What do you mean by entry-controlled and exit-controlled loop? Write a program to print the following output.(2+4)

1

01

101

0101

10101

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4. Write a program that uses a “while” loop to compute and prints the sum of a given numbers of squares. For example, if 4 is input, then the program will print 30, which is equal to 12+22+32+42


6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4) Differentiate between break and exit statement with example.

6 marks
Details
Official Answer
AI Generated Answer

AI is thinking...

4. Differentiate between while and do while loop with example.

6 marks
Details
Official Answer

Difference between while and do while loop

1. The while loop is pre-test loop, where firstly the condition is checked and if the condition is true then only the statements of the while loop execute. The do-while loop is a post-test loop. In the do-while loop, the statements of the do-while loop are executed after that, the condition is evaluated, and if the condition is true then again the statements of the do-while loop are executed.

2.

Syntax of while loop:

while (condition)

 {

   // statements

 }

Syntax of the do-while loop:

do

 {

   // statements 

 } while(condition);

3. The condition of the while loop is at the top of the loop but the condition of the do-while loop is at the bottom of the loop.

4. While loop can’t be terminated with a semicolon but the do-while loop should be terminated with a semicolon.

5. The statements of the do-while loop execute at least 1 time in every condition. In the while loop, the test expression evaluates false in first checking then the statements of the while loop is not executed. But the condition of the do-while loop is checked at the end of the loop, so it is guaranteed that the statements of the do-while loop execute at least once.

Example of while loop:

#include<stdio.h>

 int main()

 {

   int m,n;

   printf("Enter range: ");

   scanf("%d %d",&m, &n);

   while (m<=n)

   {

     if(m%2==0) 

        printf("%d ",m);

     ++m;

   }

   return 0;

 }

Example of do while loop:

 #include<stdio.h>

 int main()

 {

   int m,n;

   printf("Enter range: ");

   scanf("%d %d",&m, &n);

   do

   {

     if(m%2==0)

       printf("%d ",m);

     ++m;

   } while(m<=n);

   return 0;

 }

AI Generated Answer

AI is thinking...

    4. Differentiate break statement with continue statement. What is the output if the following program ?(2+4)

    #include<stdio.h>

    #include<conio.h>

    #include<math.h>

    void main()

    {

        int x=2, n=5, sum=0, i; clrscr();

        for(i=1; i<=n; i++)

        {

            If(i%2==0)

                sum==sum-pow(x,i);

            else

                sum=sum+pow(x,1);

           }

        Printf(“sum=%d”,sum); Getch();

    }


    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    4. Difference between if and switch statement. Write a program to read the marks of four subjects then find total, percentage and division according to given condition. [1+5]

    Percentage                                    Division

    p ≥ 80                                             Distinction

    80 > p ≥ 70                                     First division

    70 > p ≥ 50                                     Second division

    50 > p ≥ 40                                     Third division

    Otherwise Fail.

    Assume each subjects carrying 100 full marks and students must secure greater or equal to 40 in each subjects for division.

    6 marks
    Details
    Official Answer

    Difference between if and switch statement

    1. SWITCH statement is easier to express for lengthy conditions when compared to an IF statement which gets more complex as the number of conditions grow and the nested IF comes into play.

    2. SWITCH statement allows easy proofreading while testing and removing bugs from the source code whereas IF statement makes editing difficult.

    3. Expression is evaluated and SWITCH statement is run according to the result of the expression that can be integer or logical while IF statement is run only if the result of the expression is true.

    4. SWITCH allows expression to have integer based evaluation while IF statement allows both integer and character based evaluation.

    5. SWITCH statement can be executed with all cases if the ‘break’ statement is not used whereas IF statement has to be true to be executed further.

    Program

    #include <stdio.h> int main() { int phy, chem, bio, math; float p, total;

    /* Input marks of five subjects from user */ printf("Enter four subjects marks: "); scanf("%d%d%d%d", &phy, &chem, &bio, &math);

    /* Calculate total */ total= (phy + chem + bio + math); printf("Total marks = %f\\n", total); /* Calculate percentage */ p = (phy + chem + bio + math) / 4.0; printf("Percentage = %f\\n", p); /* Find division according to the percentage */ if(p >= 90) { printf("Division: Distinction"); } else if(p>=70 && p<80 ) { printf("Division: First division"); } else if(p>=50 && p<70) { printf("Division: Second division"); } else if(p>=40 && p<50) { printf("Division: Third division"); } else { printf("Fail"); } return 0; }

    AI Generated Answer

    AI is thinking...

    4. What are the four types of control statement use in C programming? Explain

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    4. Explain switch statement with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    5. Write a program that uses a do...while loop to compute and prints the sum of squares given n numbers.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    5. Differentiate between break and continue statement. Write a program to display following output.  [2+4]

    1

    1 1

    1 1 1

    1 1 1 1

    1 1 1 1 1

    6 marks
    Details
    Official Answer

    Difference between break and continue statement

    BreakContinue
    Break is used to break loop or iteration.Continue continues the loop or iteration.
    Used with switch case loop.Not used with switch case.
    Keyword used is "break".Keyword used is "continue".
    Breaks loop and allows coming out from it.Allows iterating in the loop.
    Control is transferred outside the loop.Control remains in the same loop.

    E.g.

    1. for(i=1; i<=5 ; i++) 
    2. { 
    3. if(i==3) 
    4. break; 
    5. Printf("%d\\n",i); 
    6. } 

    Output:  1, 2

    E.g.

    1. For(i=1 ;i<=5; i++) 
    2. { 
    3. if(i==3)  
    4. continue; 
    5. printf("%d\\n",i); 
    6. } 

    Output: 1, 2, 4, 5

    Program to display given output

    #include<stdio.h>

    #include<conio.h>

    #define n 5

    int main()

    {

        int i, j;

        for(i=1;i<=n;i++)

        {

            for(j=1;j<=1;j++)

            {

                printf("\\t1");

            }

            printf("\\n");

        }

        getch();

        return 0;

    }

    AI Generated Answer

    AI is thinking...

    5. What is break statement? Discuss with example. How the break statement is different from continue statement?

    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    6. Write a program to check whether a number entered is even or odd.

    5 marks
    Details
    Official Answer

    #include <stdio.h>
    int main() {
        int num;
        printf("Enter an integer: ");
        scanf("%d", &num);
        if(num % 2 == 0)
            printf("%d is even.", num);
        else
            printf("%d is odd.", num);
        
        return 0;
    }

    AI Generated Answer

    AI is thinking...

    Unit 6: Arrays
    12 Questions

    2. Define array? What are the benefits of using array? Write a program to add two matrices using array. (1+2+7)

    10 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    4. Write a program to transpose the following matrix.


                          −3   7    5      -2   8

                           2    5    8       3    -4

                         −6   9    3       6     5



    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    5. Write a program to check whether the diagonal elements of a (4*4) matrix are all Zero.

    6 marks
    Details
    Official Answer

    #include<stdio.h>

    void main()

    {

        int mat[4][4];

        int i,j,flag;

        printf("Enter the elements of the matrix\\n");

        for(i=0;i<4;i++)

        {

            for(j=0;j<4;j++)

            {

                scanf("%d",&mat[i][j]);

            }

        }

        printf("The matrix\\n");

        for(i=0;i<4;i++)

        {

            for(j=0;j<4;j++)

            {

                printf("%d\\t",mat[i][j]);

            }

            printf("\\n");

        }

        for(i=0;i<4;i++)

        {

            for(j=0;j<4;j++)

            {

                if(i==j)

                {

                    if(mat[i][j]==0)

                        flag=0;

                    else

                        flag=1;

                }

            }

        }

        if(flag==1)

            printf("The diagonal elements of matrix are not zero");

        else

            printf("The diagonal elements of matrix are all zero");

    }

    AI Generated Answer

    AI is thinking...

    5. Write a program to enter two 3x3 matrices and calculate the product of given matrices.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    5. Write a program to find the largest and smallest among the given elements in an array.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    5) Explain the multidimensional array with example. Write a program to convert a lowercase character string into uppercase.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    6. Explain the use of two dimensional arrays. Illustrate it with suitable program and explain it.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    6. Write a program to input any 10 numbers then find out greatest and smallest number. [6]

    6 marks
    Details
    Official Answer

    #include<stdio.h>

    int main()

    {

        int a[50], i, big, small;

        int n=10;

        printf("\\n\\nEnter the %d elements of the array: \\n\\n", n);

        for(i = 0; i < n; i++)

            scanf("%d", &a[i]);


        big = a[0];     // initializing

        /* from 2nd element to the last element find the bigger element than big and update the value of big */

        for(i = 1; i < n; i++)

        {

            if(big < a[i])   // if larger value is encountered

            {

                big = a[i]; // update the value of big

            }

        }

        printf("\\n\\nThe largest element is: %d", big);

        small = a[0];   // initializing

        /* from 2nd element to the last element find the smaller element than small and update the value of small*/

        for(i = 1; i < n; i++)

        {

            if(small>a[i])   // if smaller value is encountered

            {

                small = a[i];   // update the value of small

            }

        }

        printf("\\n\\nThe smallest element is: %d", small);

        return 0;

    }

    AI Generated Answer

    AI is thinking...

    6. What is array? Write a program to find the sum of each row of 3*2 matrix.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    7. Write a program to add two 3×3 matrix using function. [6]

    6 marks
    Details
    Official Answer
    #include<stdio.h>
    #include<conio.h>
    void show_matrix(int mat[3][3]);
    void add_matrix(int matA[3][3], int matB[3][3], int matSum[3][3]);
    int main()
    {
     int x[3][3], y[3][3], z[3][3];
     int i, j;
     printf("\\nEnter elements of matrix 1:\\n");
    for(i = 0; i < 3; i++)
    {
    for(j = 0; j < 3; j++)
    {
    printf("Enter elements a[%d][%d]: ", i + 1, j + 1);
    scanf("%d", &x[i][j]);
    }
    }

    printf("\\nEnter elements of matrix 2:\\n");
    for(i = 0; i < 3; i++)
    {
    for(j = 0; j < 3; j++)
    {
    printf("Enter elements b[%d][%d]: ", i + 1, j + 1);
    scanf("%d", &y[i][j]);
    }
    }
    add_matrix(x,y,z);
     printf("\\nFirst matrix is :\\n");
     show_matrix(x);
     printf("\\nSecond matrix is :\\n");
     show_matrix(y);
     printf("\\nNew addition matrix is :\\n");
     show_matrix(z);
     getch();
     return 0;
    }
    void add_matrix(int matA[3][3], int matB[3][3], int matSum[3][3])
    {
      int r,c;
      for(r=0; r<3; r++)
      {
        for(c=0; c<3; c++)
            matSum[r][c]=matA[r][c]+matB[r][c];
      }
    }

    void show_matrix(int mat[3][3])
    {
      int r,c;
      for(r=0; r<3; r++)
      {
        for(c=0; c<3; c++)
            printf(" %d",mat[r][c]);
        printf("\\n");
      }
    }
    AI Generated Answer

    AI is thinking...

    7. Write a program to calculate sum of first 10 odd numbers.

    5 marks
    Details
    Official Answer

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
        int s = 0, i;
        for (i = 1; i<10; i++)
        {
            if(i%2!=0)
            {
                s = s + i;
            }
        }
        printf("%d",s);
        getch();
    }

    AI Generated Answer

    AI is thinking...

    9. Write a program to find sum and average of 10 integer numbers stored in an array.

    5 marks
    Details
    Official Answer
    Answered by Puja Lakhe.CSIT 1st sem,BMC

    #include<stdio.h>

    int main()
    {
       int array[50],i,n=10,sum=0;
       float avg;
       //printf(" you want to sum and avg of how namy numbers?\\n");
       //scanf("%d",&n);this is for N numbers
       for(i=0;i<n;i++)
       {
        printf("enter the numbers=");
        scanf("%d",&array[i]);
       }
        for(i=0;i<n;i++)
        {
           sum=sum+array[i];
         }
       
       printf("the sum of 10 numbers you entered is=%d\\n",sum);
       avg=(float)sum/n;
       printf("the avg of the 10 numbers you entered is=%f\\n",avg);
       return 0;    
    }
    AI Generated Answer

    AI is thinking...

    Unit 7: Functions
    11 Questions

    5.Explain the functions and its types use in C programming with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    5. Explain pass by value and pass by reference with suitable example of each. (6)

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    6) Explain the library functions with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    6. Explain the user-defined functions and its types with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    6.Write a program to accept 10 number and print the sum of these numbers through function.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    7. Write and test the following power () function that returns x raised to the power n, where n can be any integer: 

    double power (double x, int p)

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    8. What is recursion? Write a program to find the factorial of given number using recursion. [2+4]

    OR

    What is pointer? Write a program to sort 'n' numbers in ascending order using dynamic memory. [2+4]

    6 marks
    Details
    Official Answer

    A function that calls itself is known as a recursive function. And, this technique is known as recursion.

    Program  to find the factorial of given number using recursion:

    #include<stdio.h>

    int fact(int);

    int main()

    {

        int x,n;

        printf(" Enter the Number to Find Factorial :");

        scanf("%d",&n);

        x=fact(n);

        printf(" Factorial of %d is %d",n,x);

        return 0;

    }

    int fact(int n)

    {

        if(n==0)

            return(1);

        return(n*fact(n-1));

    }

    ____________________________

    OR Part:

    pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location.



    program to sort 'n' numbers in ascending order using dynamic memory:

    #include<stdio.h>

    #include<stdlib.h>

    int main()

    {

          int *a,n,i,j,t;

          printf("How many numbers you want to be sorted: ");

          scanf("%d",&n);

          a=(int *)malloc(n *sizeof(int));

          printf("\\nEnter %d Numbers: \\n\\n",n);

          for(i=0;i<=n-1;i++)

          {

                scanf("%d", (a+i));

          }

          for(i=0;i<n;i++)

          {

                for(j=0;j<=i;j++)

                {

                      if(*(a+i)<*(a+j))

                      {

                            t=*(a+i);

                            *(a+i)=*(a+j);

                            *(a+j)=t;

                      }

                }

          }

          printf("\\nAfter Sorting in Ascending Order: \\n");

          for(i=0;i<n;i++)

          printf("\\n%d",*(a+i));

          return 0;

    }

    AI Generated Answer

    AI is thinking...

    8. Differentiate between call by value and call by reference with example.

    6 marks
    Details
    Official Answer

    In call by value, a copy of actual arguments is passed to formal arguments of the called function and any change made to the formal arguments in the called function have no effect on the values of actual arguments in the calling function. 

    In call by reference, the location (address) of actual arguments is passed to formal arguments of the called function. This means by accessing the addresses of actual arguments we can alter them within from the called function.

    In call by value, actual arguments will remain safe, they cannot be modified accidentally whereas In call by reference, alteration to actual arguments is possible within from called function; therefore the code must handle arguments carefully else you get unexpected results.

    Example using Call by Value:

    #include <stdio.h>

    void swapByValue(int, int); /* Prototype */

    int main() /* Main function */

    {

      int n1 = 10, n2 = 20;

      /* actual arguments will be as it is */

      swapByValue(n1, n2);

      printf("n1: %d, n2: %d\\n", n1, n2);

    } 

    void swapByValue(int a, int b)

    {

      int t;

      t = a; 

      a = b; 

      b = t;

    }

    Example using Call by Reference:

    #include <stdio.h>

    void swapByReference(int*, int*); /* Prototype */

    int main() /* Main function */

    {

      int n1 = 10, n2 = 20;

      /* actual arguments will be altered */

      swapByReference(&n1, &n2);

      printf("n1: %d, n2: %d\\n", n1, n2);

    }

    void swapByReference(int *a, int *b)

    {

      int t;

      t = *a; 

      *a = *b; 

      *b = t;

    }

    AI Generated Answer

    AI is thinking...

    8. What is function? Discuss the benefits of using function.

    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    9. Write a program to accept any number and print the sum of that number up to a single digit through recursive function.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    9. Discuss any five string library functions.

    5 marks
    Details
    Official Answer

    Five string library functions are given below:

    1. strlen(): It returns the number of characters in a string.

        syntax: strlen(string_name)

    2. strcpy():  It copies the contents of source string to destination string.

        syntax: strcpy(destination_string, source_string)

    3. strcat(): It concats or joins first string with second string. The result of the string is stored in first string.

        syntax: strcat(first_string, second_string)

    4. strcmp(): It compares the first string with second string. If both strings are same, it returns 0.

        syntax:  strcmp(first_string, second_string)

    5. strstr(): It is used to search whether a substring is present in the main string or not.

        syntax: strstr(mainsring, substring)

    AI Generated Answer

    AI is thinking...

    Unit 8: Structure and Union
    9 Questions

    3. What is structure? How is it different from array? Create a structure student having data members name, roll-number and percentage. Complete the program to display the name of student having percentage greater than or equal to 60.

    10 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    8. Explain the passing structure to function with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    9) Explain the array of structures and write a program to accept record of 15 person which has name, age and address and also display them.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    9. Why structure is required? Make a program using structure of booklist having data member’s title, author, and cost. Enter four data and calculate total cost.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    9. Define a structure of student having data members, name, address, marks in C language, and marks in information system. Take data for n students in an array dynamically and find the total marks obtained.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    9. What is structure? How is it different from array and Union? Discuss

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    10. Write short notes on:

      a) Documentation

      b) Structure

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    10. Explain the passing structure to function with example.

    OR

    Write short notes on:

    a. Graphics function       b. Formatted I/O

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    11. What is structure? Create a structure rectangle with data members length and breadth.

    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    Unit 9: Pointers
    13 Questions

    6. What is the function of a pointer variable? Explain the declaring and initializing pointers with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    7) Write a program to find the sum of all the elements of an array using pointers.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    7. Explain the use of pointer in c programming. How can your declare the pointer? Explain with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    7. What is dynamic memory allocation? Write a program to find sum and average of n numbers entered from the keyboard using dynamic memory allocation to create array to store these n numbers.(2+4)

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    7. Write a program to accept two numbers and sort them with using pointer.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    7. Write a program using pointers to read in an array of integers and print its elements in reverse order.

    6 marks
    Details
    Official Answer

    #include<stdio.h>

    #include<conio.h>

    #define MAX 30

    void main()

    {

      int size, i, arr[MAX];

      int *ptr;

      clrscr();

      ptr=&arr[0];

      printf("Enter the size of array : ");

      scanf("%d",&size);

      printf("Enter %d integers into array:n",size);

       for(i=0;i<size;i++)

       {

       scanf("%d",ptr);

       ptr++;

       }

      ptr=&arr[size-1];

      printf("Elements of array in reverse order are:n");

      for(i=size-1;i>=0;i--)

       {

       printf("nElement%d is %d :",i,*ptr);

       ptr--;

       }

      getch();

    }

    AI Generated Answer

    AI is thinking...

    8. Justify the pointer is jewel of C language. Write a function that is passed an array of pointers to floats and returns a newly created array that contains those n float values in reverse order. Assume any necessary data.

    OR

    Explain pointer with suitable diagram. Write a function that uses pointers to search for the address of a given integer in a given array. If the given integer is found, the function returns its address; otherwise it returns NULL.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    8) Explain the pointer arithmetic with example.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    8. Why pointer is called jewel of C language? Write a program that uses pointers to copy an array of integer.

    OR

    Explain the importance of pointer. Write a function that is passed an array of pointers to floats and returns a newly created array that contains those n float values.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    8. Write a program to accept 10 numbers and show them with using pointer.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    10. Explain the pointer to structure with example.

    OR

    Write short notes on:

    a) Dynamic memory allocation b) Opening and Closing file

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    10. What is dynamic memory allocation? Discuss the use of malloc() in dynamic memory allocation with example.

    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    10. Define pointer. Discuss the relationship between pointer and one-dimensional array.

    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    Unit 10: File Handling in C
    2 Questions

    3. Why do we need data files? What are the different file opening modes? Write a program that reads data from a file "input.txt" and writes to "output.txt" file.

    10 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    11. Write a program to read and print data stored in a file input.txt.

    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    Unit 11: Introduction to Graphics
    5 Questions

    9. Discuss with example any five graphics function used in c-programming. (6)

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    10. Define the graphics function. Write a program to draw a circle using graphics function.

    6 marks
    Details
    Official Answer

    C graphics using graphics.h functions can be used to draw different shapes, display text in different fonts, change colors and many more. Using functions of graphics.h in Turbo C compiler we can make graphics programs, animations, projects, and games. We can draw circles, lines, rectangles, bars and many other geometrical figures. We can change their colors using the available functions and fill them. 

    Program to draw a circle using graphics function

    #include <stdio.h>

    #include <graphics.h>

    main()

    {

        int gd = DETECT, gm;

        initgraph(&gd, &gm, "C:\\TC\\BGI");

        circle(100, 100, 50);

        getch();

        closegraph();

        return 0;

    }

    AI Generated Answer

    AI is thinking...

    10. Create a text file and enter “to write a good program is very time consuming job”. Create another text which contains reverse of above text.

    OR 

    Explain the use of graphical function. Make a program that contains basic graphic functions.

    6 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    12. Why do we need graphics functions? Write a program to draw a circle.

    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...

    12. Write short notes on:

    (a) Benefits of data files 

    (b) Graphics functions.


    5 marks
    Details
    Official Answer
    AI Generated Answer

    AI is thinking...