C program to Sort Names in Alphabetical Order

Write a C program to sort names in alphabetical order. This example allows entering multiple strings or names and sorting them in alphabetical order using for loop. The if statement (if (strcmp(str[i], str[j]) > 0) ) compares each string with the other. The strcpy function will copy that string to temp and then alter their … Read more

C Program to Sort an Array using a Pointer

Write a C program to sort an array using a pointer. This c example passes the pointer to the SortArray function and uses the temp variable inside the for loop to sort the array in ascending order. #include <stdio.h> void SortArray(int Size, int* parr) { int i, j, temp; for (i = 0; i < … Read more

C Program to Find the Second Smallest Element in an Array

Write a C program to find the second smallest element in an array using for loop. In this example, the if statement checks whether items are smaller than the smallest variable and stores the second smallest array element. #include <stdio.h> #include <limits.h> int main() { int i, Size; int smallest, secSmallest; printf(“\nEnter Second Smallest Number … Read more

C Program to Read and Print Array Elements using a Pointer

Write a C program to read and print array elements using a pointer. In this c example, we will print array elements using a pointer and for loop. arr[0] is equivalent to *arr Insert Element at arr[1] = arr + 1 and Printing arr[1] = *(arr + 1) Insert Element at arr[2] = arr + … Read more

C Program to Reverse a Number using Recursive Function

Write a C program to reverse a number using a recursive function. In this C example, the user-defined function accepts the integer and iterates the value recursively to reverse the given number. On each iteration, the reverse variable will collect the last digit of a number. #include <stdio.h> int rem, reverse = 0; int reverse_number(int … Read more

C Program to Find Sum of 10 Numbers and Skip Negative Numbers

Write a c program to find sum of 10 numbers and skip negative numbers using for loop. In this c example, for loop iterate from 1 to 10, the if statement checks whether the number is less than zero. If true, the continue statement will skip that number to perform addition. #include <stdio.h> int main() … Read more

C Program to Read 10 Numbers and Find their Sum and Average

Write a C program to read 10 numbers and find their sum and average using for loop. In this example, for loop iterate from 1 to 10, add each number to the sum to find the sum of 10 numbers. Next, we calculate the average. #include <stdio.h> int main() { int num, sum = 0; … Read more

C program to Print String using Pointer

Write a C program to print string using a pointer. In general, we use a loop to iterate each character index of the string array. In this example, we assigned the string array address to the pointer. Next, we used a while loop to print each character by incrementing the pointer. #include <stdio.h> int main() … Read more

C Program to Print 2D Array Elements

Write a C program to print 2D array elements or two-dimensional array items using for loop. In this c example, the first for loop iterates rows, and the second loop iterates columns. Within the C for loop, we print the 2D array elements, and we insert a new line (printf(“\n”)) for each row iteration. #include<stdio.h> … Read more