prathmeshyelne has Published 59 Answers

Find Second largest element in an array using C Programming

Updated on 17-Nov-2022 15:54:01
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 22-Dec-2021 18:23:52
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 22-Dec-2021 13:09:28
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 22-Dec-2021 9:01:45
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 Quotient and Remainder

Updated on 21-Dec-2021 14:21:21
In this example, you will learn to find the quotient and remainder of a given dividend and divisor. In this program, the user is asked to enter two integers (divisor and dividend) and the quotient and the remainder of their division is computed. To compute quotient and remainder, both divisor and dividend should be integers. Program :  #include <iostream> using namespace std; int main() { int divisor, dividend, quotient, remainder; cout << "E... Read More

Write C++ Program to Add Two Numbers

Updated on 21-Dec-2021 13:11:20
In this program, user is asked to enter two integers. Then, the sum of those two integers is stored in a variable and displayed on the screen. #include <iostream> using namespace std; int main() { int firstNumber, secondNumber, sumOfTwoNumbers; cout << "Enter two integers: "; cin >> firstNumber >> secondNumber; // sum of two numbers in stored in variable sumOfTwoNumbers sumOfTwoNumbers = firstNumber + secondNumber; // Prints... Read More

Write C++ Program to Print Number Entered by User

Updated on 21-Dec-2021 13:01:07
In this example, you'll learn to print the number entered by a user using C++ cout statement. Program : #include <iostream> using namespace std; int main() { int number; cout << "Enter an integer: "; cin >> number; cout << "You entered " << number; return 0; } Output : Enter an integer: 23 You entered 23 Explanation : This program asks the user to enter a number. When the user enters an integer, it is stored ... Read More

Write a program in C++ to print Hello World

Updated on 21-Dec-2021 12:06:30
Program : To print hello world using C++ // Your First C++ Program #include int main() { std::cout << "Hello World!"; return 0; } Output : Hello World! Explanation: 1. // Your First C++ Program In C++, any line starting with // is a comment. Comments are intended for the person reading the code to better understand the functionality of the program. It is completely ignored by the C++ compiler. 2. #include The #include is a preprocessor directive use... 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
1 2 36 Next
Advertisements