C Programming 2075
Attempt any two questions:
1. What is looping statement? Discuss different looping statements with suitable example of each. (2+8)
2. Define array? What are the benefits of using array? Write a program to add two matrices using array. (1+2+7)
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.
Attempt any eight questions:
4. Discuss different logical operators in detail.
5. What is break statement? Discuss with example. How the break statement is different from continue statement?
6. Write a program to check whether a number entered is even or odd.
#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.
#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.
9. Discuss any five string library functions.
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.
11. What is structure? Create a structure rectangle with data members length and breadth.
12. Write short notes on:
(a) Benefits of data files
(b) Graphics functions.