



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 6
This page cannot be seen from the preview
Don't miss anything!
① 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:
int main () { char a [] = "ABC" ; printf ("%s\n", a); return 0 ; }
OUTPUT: ABC
● Str cat() ● Str rev () ● Str lwr () ● Str upr()
Str upr():
#include<stdio.h>
int main() { char str[]=”hello world”; printf(“%s\n”,strupr(str)); return 0; }
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.
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; }