Top 10 Programming Language to learn in 2023

Are you a programming enthusiast looking to stay ahead of the curve in 2023? With the ever-evolving tech landscape, keeping up with the Best Programming Language to learn can be a daunting task. Fear not, as we have compiled a list of the top 10 Programming Languages that you should consider learning in 2023. Python: This versatile language continues to dominate in 2023, with its ease of use, readability, and a vast library of modules. JavaScript: As web development grows increasingly popular, JavaScript remains a crucial player, with its ability to create dynamic and interactive web pages. Java: This language has stood the test of time and remains a popular choice for enterprise software development. C++: A staple in the gaming and systems development industries, C++ offers exceptional performance and memory management. Swift: Apple's preferred language for iOS app development, Swift continues to grow in popularity with its simplicity and reliability. R: As data science and machin...

Linear Search in C Programming | C Programming

Linear search in C Programming

Linear search in C programming: The following code implements linear search (Searching algorithm) which is used to find whether a given number is present in an array and if it is present then at what location it occurs. It is also known as sequential search. It is straightforward and works as follows: We keep on comparing each element with the element to search until it is found or the list ends. Linear search in C language for multiple occurrences and using function.





Linear search C program 

span style="color: #339933;">#include<stdio.h>


int main()
{
int array[100], search, c, n;

printf("Enter the number of elements in array\n");
scanf("%d",&n);

printf("Enter %d integer(s)\n", n);

for (c = 0; c < n; c++)
scanf("%d", &array[c]);

printf("Enter the number to search\n");
scanf("%d", &search);

for (c = 0; c < n; c++)
{
if (array[c] == search) /* if required element found */
{
printf("%d is present at location %d.\n", search, c+1);
break;
}
}
if (c == n)
printf("%d is not present in array.\n", search);

return 0;
}
Download Linear search program.
Output of program:
linear Search in C
C program for binary search

Linear search for multiple occurrences

In the code below we will print all the locations at which required element is found and also the number of times it occur in the list.
#include<stdio.h>

int main()
{
int array[100], search, c, n, count = 0;

printf("Enter the number of elements in array\n");
scanf("%d", &n);

printf("Enter %d numbers\n", n);

for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);

printf("Enter the number to search\n");
scanf("%d", &search);

for (c = 0; c < n; c++) {
if (array[c] == search) {
printf("%d is present at location %d.\n", search, c+1);
count++;
}
}
if (count == 0)
printf("%d is not present in array.\n", search);
else
printf("%d is present %d times in array.\n", search, count);

return 0;
}
Download Linear search multiple occurrence program.
Output of code:
linear Search in C for multiple occurrence

C program for linear search using function

#include<stdio.h>

long linear_search(long [], long, long);

int main()
{
long array[100], search, c, n, position;

printf("Input number of elements in array\n");
scanf("%ld", &n);

printf("Input %d numbers\n", n);

for (c = 0; c < n; c++)
scanf("%ld", &array[c]);

printf("Input number to search\n");
scanf("%ld",&search);

position = linear_search(array, n, search);

if (position == -1)
printf("%d is not present in array.\n", search);
else
printf("%d is present at location %d.\n", search, position+1);

return 0;
}

long linear_search(long a[], long n, long find) {
long c;

for (c = 0 ;c < n ; c++ ) {
if (a[c] == find)
return c;
}

return -1;
}


Comments

Popular posts from this blog

Array in C Programming | C Programming

C program to Find Cartesian Product of Two Sets | C programming

What is System? | SAD