Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

PROGRAMMING IN C (PRACTICE ASSIGNMENT 3 ) FOR EXAMS (BTPS101-18), Study notes of C programming

THIS PDF IS FOR C PROGRAMMING. IT INCLUDES QUESTIONS WITH DETAILED ANSWERS FOR C THAT IS IMPORTANT FOR EXAM POINT OF VIEW. QUESTIONS INCLUDES FROM ARRAY .STRING HANDLING FUNCTIONS , SEARCHING,SORTING ETC. MY NOTES IS EASY TO UNDERSTAND AND IS REASONABLE WITH THE PRICE. CHECK IT OUT .

Typology: Study notes

2024/2025

Available from 07/04/2025

KANOYA2786
KANOYA2786 🇮🇳

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROGRAMMING TO PROBLEM SOLVING (C) SOME IMP
PRACTICE QUESTIONS (TOPICS- BUBBLE SORT ,BINARY AND
LINEAR SEARCH,ARRAY,STRING HANDLING FUNCTIONS)
1.WHAT IS CHARACTER ARRAY AND WRITE ITS SYNTAX?
2. NAME AND WRITE TWO STRING HANDLING FUNCTIONS WITH
THE HELP OF SUITABLE EXAMPLE.
3.EXPLAIN BINARY SEARCH WITH THE HELP OF EXAMPLE AND
WRITE ITS ALGORITHM.
4.COMPARE LINEAR AND BINARY SEARCH.
5.CONSTRUCT A PROGRAM FOR BUBBLE SORT.
SOLUTIONS:-
ARRAY: To process a large amount of data, we need a data Structure known as Array.
CONDITIONS:
The data elements have the same datatype.
The elements of the array are stored in continuous memory locations
referred as index.
CHARACTER ARRAY:
In character array, we use characters that can be alphabets, numerics, and Special symbols.
SYNTAX:
datatype arrayname [size];
For example: char a[10];
pf3
pf4
pf5

Partial preview of the text

Download PROGRAMMING IN C (PRACTICE ASSIGNMENT 3 ) FOR EXAMS (BTPS101-18) and more Study notes C programming in PDF only on Docsity!

PROGRAMMING TO PROBLEM SOLVING (C) SOME IMP

PRACTICE QUESTIONS (TOPICS- BUBBLE SORT ,BINARY AND

LINEAR SEARCH,ARRAY,STRING HANDLING FUNCTIONS)

1.WHAT IS CHARACTER ARRAY AND WRITE ITS SYNTAX?

2. NAME AND WRITE TWO STRING HANDLING FUNCTIONS WITH

THE HELP OF SUITABLE EXAMPLE.

3.EXPLAIN BINARY SEARCH WITH THE HELP OF EXAMPLE AND

WRITE ITS ALGORITHM.

4.COMPARE LINEAR AND BINARY SEARCH.

5.CONSTRUCT A PROGRAM FOR BUBBLE SORT.

SOLUTIONS:-

ARRAY: To process a large amount of data, we need a data Structure known as Array. CONDITIONS:

● The data elements have the same datatype. ● The elements of the array are stored in continuous memory locations referred as index.

CHARACTER ARRAY: In character array, we use characters that can be alphabets, numerics, and Special symbols. SYNTAX: datatype arrayname [size]; For example: char a[10];

→ char name [6] = { 'H' , 'e' , 'l' , 'l' , 'o' , '\0' }; (5+1=6, 10-Null) ② STRING: Every string can be implemented using character array because string is a combination of Characters.

For example:

include <stdio.h>

int main () { char a [] = "ABC" ; printf ("%s\n", a); return 0 ; }

OUTPUT: ABC

The string handling functions:

● Str cat() ● Str rev () ● Str lwr () ● Str upr()

Str upr():

#include<stdio.h>

include <string.h>

int main() { char str[]=”hello world”; printf(“%s\n”,strupr(str)); return 0; }

OUTPUT: HELLO WORLD

for (i = 0 ; i < size; i++) { scanf("%d",&list[i]); }

printf ("Enter the element to search : "); scanf("%d", & selement);

low= 0 ; high=size-1;

while (low<=high) { mid=(low+high)/ 2 ; if (list [mid] == selement) { found = 1 ; printf("Element %d found at position %d.\n", selement, mid); break; } else if (list [mid] < selement) { low=mid+ 1 ; } else { high = mid-1; } } if (!found) { printf("Element not found \n"); } }

OUTPUT: Enter the size: 5 Enter the elements: 5 6 7 8 18 Enter the element to search: 8 Element 8 found at position 3

LINEAR SEARCH BINARY SEARCH

  • Linear search is also known as sequential search.

  • An algorithm that works efficiently with a sorted list.

It works by comparing the value to be searched 'key' with every element of the array one by one until a match is found.

As linear search is a time-taking process. To shorten this process, we use binary search in which we divide our elements in two halves.

Linear search is mostly used to search an unordered list.

sorting: sorting means arranging an array so that they are placed in some order which may be ascending or descending. Sorting

● Bubble Sort ● Selection Sort ● Insertion Sort

Bubble sort: Bubble sort is a very simple method that sorts the array repeatedly moving the largest elements to the highest index position of the array segment.

For example: In bubble sort, consecutive adjacent elements in the array are compared with each other if the element at the lower index is greater than the element at a higher index. The two elements are swapped with each other.

include <stdio.h>

int main() { int a[ 5 ]={ 5 , 2 , 15 , 22 , 1 } ; int i, j,temp; for(i= 4 ;i> 0 ;i--) { for (j= 0 ;j<=i-1;j++) if (a[j]>a[j+ 1 ]) { temp=a[j]; a[j]=a[j+ 1 ]; a[j+ 1 ]=temp; }