QB - Computer Programming (NEP)
UNIT I
Explain basic structure of C program with example.
What is the difference between keyword and identifier?
What are keywords in C? Why are they important?
Explain following terms with example :
i. Constants
ii. Variable
Explain basic Data Types in C.
What is an operator in C? List the different types of operators available in C.
What are the basic input and output functions in C? Explain their usage.
What are built-in functions in C?
C Programs
Write a C program to swap the values of two variables.
Write a C program to calculate the simple interest for a given principal, rate of interest, and time period.
Write a C program that converts a given temperature in Celsius to Fahrenheit using the expression
Fahrenheit = (Celsius * 9/5) + 32.
C Find the Output
#include <stdio.h>
#define PI 3.14
int main() {
float r = 2.0;
printf("Area = %.1f\n", PI * r * r);
return 0;
}
#include<stdio.h>
void main()
{
int i = 15, j = 4 , m, n;
m = i > 9;
n = j > 4 && j!=2;
printf("m = %d n = %d",m,n);
}
--------------------------------------------------------------------------------------------------------------------------------------
UNIT II
Explain the working of switch - case with syntax and example.
Give the difference between ‘while loop’ and ‘do while loop’ with example.
Explain jump statements - continue, break, goto, exit().
Give the difference between ‘continue’ and ‘break’ with example.
What is a concise test expression in C? Explain with an example.
C Programs
Write a C program to find the largest of three numbers using the ternary operator (? :)
Write a C program to calculate the factorial of a number using a loop.
Write a C program to check whether a given year is a leap year or not.
Write a C program to calculate the sum of digits of a given number.
Write a C program to enter any number and print its reverse.
C Find the Output
#include <stdio.h>
int main() {
int x = 10, y = 20, z = 5;
printf("%d\n", x > y ? x : y < z ? y : z);
return 0;
}
#include <stdio.h>
int main() {
int x = 2;
switch (x) {
case 1: printf("One"); break;
case 2: printf("Two");
default: printf("Default");
}
return 0;
}
#include <stdio.h>
int main() {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (j == 2) {
continue;
}
printf("%d %d\n", i, j);
}
}
return 0;
}
#include <stdio.h>
int main() {
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
if (j == 2) {
break;
}
printf("%d %d\n", i, j);
}
}
return 0;
}
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
break;
}
printf("%d ", i);
}
return 0;
}
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
continue;
}
printf("%d ", i);
}
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------
UNIT III
Define an Array. What is a One-Dimensional array in C? How is it declared and accessed?
What is a Two-Dimensional array in C? How is it different from a One-Dimensional array?
What is a Multi-Dimensional array in C? How is it declared and accessed?
C Programs
Write a C program to find the largest and smallest elements in an array.
Write a C program to calculate the average of an array of numbers.
Write a C program to check if an array is a palindrome or not.
Write a C program to merge two sorted arrays into a single sorted array.
Write a C program to find the transpose of a matrix.
Write a C program to add two matrices
C Find the Output
#include <stdio.h>
int main() {
int arr[] = {5, 10, 15, 20, 25};
printf("%d\n", arr[2]);
printf("%d\n", arr[4]);
printf("%d\n", arr[1] + arr[3]);
printf("%d\n", arr[0] * arr[4]);
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------
UNIT IV
What is a string in C? How does it differ from a character array?
List and Explain string library functions with proper syntax and example.
What is the purpose of the null character ('\0') in C strings?
Explain how to read a string from the terminal and display it on the screen in C.
Explain the difference between strupr() and strlwr() functions in C. Provide examples of their usage.
How can you compare two strings up to a specified number of characters using strncmp() in C?
C Programs
Write a C program to reverse a given string without using built-in string function.
Write a C program to find the length of a string without using built-in string function.
Write a C program to check if a string is a palindrome.
Write a C program to convert a given string to uppercase and lowercase.
Write a C program to count the number of vowels and consonants in a string.
C Find the Output
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
printf("%c", str[7]);
return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------
UNIT V
What is a function in C? Explain with example call by reference function call.
What is a function in C? Explain with example call by value function call.
Explain the difference between pass by value and pass by reference in function calls.
Explain recursive functions with example.
What is pointer? Explain with example.
What is pointer to pointer? Explain with example.
C Programs
Write a C program to swap two numbers using a function.
Write a program in C to find the length of a string using pointers.
Write a C program that prints the Fibonacci series using a recursive function.
C Find the Output
#include<stdio.h>
main()
{
printf(“\n computer”);
main();
}
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int *ptr = arr;
printf("%d %d\n", *(ptr+1), *(ptr + 3));
return 0;
}
#include<stdio.h>
main()
{
char text[] = "Welcome";
int num[] = {10, 20, 30, 40, 50, 60, 70};
int i;
for(i = 0; i < 7; i++)
printf("Element no. %d, value = %c\n", i+1, *(text+i));
for(i = 0; i < 7; i++)
printf("Element no. %d, value = %d\n", i+1, *(num+i));
}
--------------------------------------------------------------------------------------------------------------------------------------
UNIT VI
Explain the difference between declaration and definition of structure?
What is union? Differentiate the difference between structure and union.
Write typedef and struct declaration for Customers in a bank.
Define a struct and use typedef to represent a Book, including details such as title, author, publication year,
and price.
Explain the functions used for opening and closing files in C.
How can you read data from a file in C? Explain with an example using fgetc() and fgets().
How can you write data to a file in C? Explain with an example using fputc() and fputs().
What is the purpose of the fseek() and ftell() functions in C?
C Programs
Write a C program to store and display employee details using structures.
Write a C program to copy the contents of one text file to another.
Write a C program to read and display the contents of a text file.