prathmeshyelne has Published 58 Answers

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

Published 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... Read More

Write C Program to Merge Two arrays in C Programming

Published 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... Read More

Write C Program to Reversing an Array Elements in C Programming

Published 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++; // in... Read More

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

Published 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 pri... Read More

Write C++ Program to Find Quotient and Remainder

Published 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, divi... Read More

Write C++ Program to Add Two Numbers

Published 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 sumOfTwoNumb... Read More

Write C++ Program to Print Number Entered by User

Published 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.... Read More

Write a program in C++ to print Hello World

Published 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. #inclu... Read More

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

Published 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) { sm... Read More

Write C Program to Calculate Addition of All Elements in Array

Published 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 a... Read More
1 2 3 6