C Programming 2075

Tribhuwan University
Institute of Science and Technology
2075
Bachelor Level / First Semester / Science
Computer Science and Information Technology ( CSC110 )
( C Programming )
Full Marks: 60
Pass Marks: 24
Time: 3 hours
Candidates are required to give their answers in their own words as far as practicable.
The figures in the margin indicate full marks.

Attempt any two questions:

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

10 marks view

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

10 marks view

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 view

Attempt any eight questions:

4. Discuss different logical operators in detail.

5 marks view

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

5 marks view

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

5 marks view

#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;
}

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

5 marks view

#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();
}

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

5 marks view

9. Discuss any five string library functions.

5 marks view

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)

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

5 marks view

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

5 marks view

12. Write short notes on:

(a) Benefits of data files 

(b) Graphics functions.


5 marks view