Found 34 Questions For C Programming

C Program To Print Your Own Name

Updated on 07-Apr-2023 15:15:28
In C programming language, we can use the scanf() and printf() functions to take input and output data respectively. In this article, we will write a C program to print your own name using these two functions in two way. Example 1: In this example, we print the user name using printf() function. // C program to demonstrate printing of // our own name using printf() #include <stdio.h> int main() { // print name printf("Name : Codegyan"); return 0; } Output :  Name :... Read More

Write C Program For Finding The Length Of Loop In Linked List

Updated on 02-Apr-2023 15:08:05
Introduction: Linked lists are data structures that store data elements in a linear manner. Each element of a linked list, known as a node, consists of two parts: data and a pointer that points to the next node in the list. A linked list can have one or more loops or cycles, where a node points to a previously visited node in the list. In this article, we will discuss how to find the length of a loop in a linked list using C programming language. Algorithm: To find the length of a loop in a link... Read More

Write C program to Check Whether a Number is Positive or Negative

Updated on 10-Feb-2023 13:46:26
In this tutorial we'll learn how to check whether a given integer is positive or negative. We have the the number that we need to check that integer is positive or negative number using c program. Problem Description The program takes the given integer and checks whether the integer is positive or negative. Problem Solution 1. Take the integer which you want to check as input. 2. Check if it is greater or lesser than zero and print the output accordingly. 3. Exit. Program/So... Read More

Find Second largest element in an array using C Programming

Updated on 12-Jan-2023 0:25:36
Given an array of integers, our task is to write a program that efficiently finds the second largest element present in the array. Example: Input: arr[] = {12, 35, 1, 10, 34, 1} Output: The second largest element is 34. Explanation: The largest element of the array is 35 and the second largest element is 34 Input: arr[] = {10, 5, 10} Output: The second largest element is 5. Explanation: The largest element of the array is 10 and the second largest element is 5 Input: arr[] =... Read More

Recursive program to linearly search an element in a given array using C

Updated on 15-Feb-2022 16:04:30
Given an unsorted array and an element x, search x in given array. Write recursive C code for this. If element is not present, return -1. Approach : The idea is to compare x with the last element in arr[]. If an element is found at the last position, return it. Else recur elmntSrch() for remaining array and element x. Program : /* * Approach : The idea is to compare x with the last element in arr[]. * If an element is found at the last position, return it. * Else recur el... Read More

Write C Program to Merge Two arrays in C Programming

Updated on 17-Jan-2022 9:28:10
Program : C Program to Merge Two arrays in C Programming #include<stdio.h> int main() { int arr1[30], arr2[30], res[60]; int i, j, k, n1, n2; printf("\nEnter no of elements in 1st array :"); scanf("%d", &n1); for (i = 0; i < n1; i++) { scanf("%d", &arr1[i]); } printf("\nEnter no of elements in 2nd array :"); scanf("%d", &n2); for (i = 0; i < n2; i++) { scanf("%d", &arr2[i]); } i = 0; j = 0; k = 0; // Merging starts while (i < n1 &... Read More

Write C Program to Reversing an Array Elements in C Programming

Updated on 17-Jan-2022 9:13:54
Program : Reversing an Array Elements in C #include<stdio.h> int main() { int arr[30], i, j, num, temp; printf("\nEnter no of elements : "); scanf("%d", &num); //Read elements in an array for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } j = i - 1; // j will Point to last Element i = 0; // i will be pointing to first element while (i < j) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; // increment i j--; // decrement j } //Print out t... Read More

Write C Program to Find Largest Element in Array in C Programming

Updated on 17-Jan-2022 9:02:21
Program : Find Largest Element in Array in C Programming #include<stdio.h> int main() { int a[30], i, num, largest; printf("\nEnter no of elements :"); scanf("%d", &num); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); //Consider first element as largest largest = a[0]; for (i = 0; i < num; i++) { if (a[i] > largest) { largest = a[i]; } } // Print out the Result printf("\nLargest Element : %d", largest); return ... Read More

Write C Program to Find Smallest Element in Array in C Programming

Updated on 20-Dec-2021 20:18:00
Program : Find Smallest Element in Array in C Programming #include <stdio.h> int main() { int a[30], i, num, smallest; printf("\nEnter no of elements :"); scanf("%d", &num); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); //Consider first element as smallest smallest = a[0]; for (i = 0; i < num; i++) { if (a[i] < smallest) { smallest = a[i]; } } // Print out t... Read More

Write C Program to Calculate Addition of All Elements in Array

Updated on 20-Dec-2021 20:11:22
Program : Addition of All Elements of the Array #include <stdio.h> int main() { int i, arr[50], sum, num; printf("\nEnter no of elements :"); scanf("%d", &num); //Reading values into Array printf("\nEnter the values :"); for (i = 0; i < num; i++) scanf("%d", &arr[i]); //Computation of total sum = 0; for (i = 0; i < num; i++) sum = sum + arr[i]; //Printing of all elements of array for (i = 0; i < num; i... Read More
1 2 3 4 Next



Advertisements

ads