Found 26 Questions For Programming

How To Reduce the Array to 0 by decreasing elements by 1 or replacing at most K elements by 0

Updated on 14-Nov-2022 19:30:10
Given an array arr[ ] of N integers and a positive integer K, the task is to find the minimum number of operations required to reduce all array elements to 0 such that in each operation reduce any array element by 1 and independently at most K array element can be reduced to 0. Examples: Input: arr[ ] = {4, 1, 5}, K = 1 Output: 5 Explanation: Following are the operations performed to convert all array elements to 0: Here K = 1, So replace arr[2] by 0, converts arr[v] to {... 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 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 a C program using pointers to read in an array of integers and print its elements in reverse order.

Updated on 19-Dec-2021 17:39:45
#include <stdio.h> #include <conio.h> #define MAX 30 void main() { int size, i, arr[MAX]; int *ptr; clrscr(); ptr = &arr[0]; printf("\nEnter the size of array : "); scanf("%d", &size); printf("\nEnter %d integers into array: ", size); for (i = 0; i < size; i++) { scanf("%d", ptr); ptr++; } ptr = &arr[size - 1]; printf("\nElements of array in reverse order are :"); for (i = size - 1; i >= 0; i--) { printf("\nElement... Read More

How to Implement Stack Operations Using Array using C

Updated on 18-Dec-2021 18:27:23
Program for implementing a stack using arrays.It involves various operations such as push,pop,stack empty,stack full and display. #include <stdio.h> #include <conio.h> #include <stdlib.h> #define size 5 struct stack { int s[size]; int top; } st; int stfull() { if (st.top >= size - 1) return 1; else return 0; } void push(int item) { st.top++; st.s[st.top] = item; } int stempty() { if (st.top == -1) return 1... Read More

How to calculate sum of 5 subjects and find percentage Using C Program

Updated on 16-Dec-2021 16:02:43
C Program to calculate sum of 5 subjects and find percentage #include <stdio.h> int main() { int s1, s2, s3, s4, s5, sum, total = 500; float per; printf("\nEnter marks of 5 subjects : "); scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5); sum = s1 + s2 + s3 + s4 + s5; printf("\nSum : %d", sum); per = (sum * 100) / total; printf("\nPercentage : %f", per); return (0); } Output : Enter marks of 5 subjects : 80 70 90 8... Read More

How to calculate gross salary of a person using C Program

Updated on 16-Dec-2021 15:48:12
#include <stdio.h> int main() { int gross_salary, basic, da, ta; printf("Enter basic salary : "); scanf("%d", &basic); da = (10 * basic) / 100; ta = (12 * basic) / 100; gross_salary = basic + da + ta; printf("\nGross salary : %d", gross_salary); return (0); } Output : Enter basic Salary : 1000 Gross Salart : 1220 ... Read More

How to reads customer number and power consumed and prints amount to be paid using C

Updated on 16-Dec-2021 15:41:24
An electric power distribution company charges its domestic consumers as follows Consumption Rate of Units Charge ------------------------------------ 0-200 Rs.0.50 per unit 201-400 Rs.100 plus Rs.0.65 per unit excess 200 401-600 Rs.230 plus Rs.0.80 per unit excess of 400. ------------------------------------ Write a C program that reads the customer number and power consumed and prints the amount to be paid by the customer. P... Read More

How to read the values of x, y and z and print the results expressions in one line using C Program

Updated on 16-Dec-2021 15:31:37
Problem Statement : Write a program to read the values of x, y and z and print the results of the following expressions in one line. (x+y+z) / (x-y-z) (x+y+z) / 3 (x+y) * (x-y) * (y-z) Program : #include<stdio.h> #include<conio.h> void main() { int x, y, z; float a, b, c; clrscr(); printf("\nEnter the values of x,y and z : "); scanf("%d %d %d", &x, &y, &z); a = (x + y + z) / (x - y - z); b = (x + y + z) / 3; c = (x + y) * (x - y) ... Read More

What is SQL ?

Updated on 12-Dec-2021 19:28:20
SQL stands for Structured Query Language. It is the primary language to interact with databases. With the help of SQL, we can extract data from a database, modify this data and also update it whenever there is a requirement. This query language is evergreen and is widely used across industries. For example, if a company has records of all the details of their employees in the database. With the help of SQL, all of this data can be queried to find out valuable insights in a short span of time... Read More
1 2 3 Next
Advertisements