Name:-Shushant Sonwani
Name:-Shushant Sonwani
1.
#include <stdio.h>
int main() {
int arr[] = {1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0};
int n = sizeof(arr) / sizeof(arr[0]);
moveZeroesToEnd(arr, n);
printf("\n");
return 0;
}
2.
#include <stdio.h>
int main() {
int arr[] = {1, 5, 3, 4, 2};
int n = sizeof(arr) / sizeof(arr[0]);
int k = 3;
return 0;
}
3.
#include <stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5, 6, 7};
int n = sizeof(arr) / sizeof(arr[0]);
int k = 2;
rotateArray(arr, n, k);
printf("\n");
return 0;
}
4.
#include <stdio.h>
int main() {
int matrix[3][3];
int sum = 0;
printf("Enter a 3x3 matrix:\n");
return 0;
}
6.
#include <stdio.h>
int main() {
int n;
int arr[n];
// Input the array elements
printf("Enter the elements of the array:\n");
for (int i = 0; i < n; i++) {
printf("Element %d: ", i + 1);
scanf("%d", &arr[i]);
}
6.
#include <stdio.h>
int main() {
int n;
printf("Enter the size of the array: ");
scanf("%d", &n);
if (n <= 0) {
printf("Invalid array size.\n");
return 1;
}
int arr[n];
return 0;
}
7.
#include <stdio.h>
#include <stdlib.h>
int temp = m;
m = n;
n = temp;
}
int i, j, min_index, max_index, mid_index, median;
min_index = 0;
max_index = m;
median = 0;
int main() {
int X[] = {1, 3, 8};
int Y[] = {7, 9, 10};
int m = sizeof(X) / sizeof(X[0]);
int n = sizeof(Y) / sizeof(Y[0]);
return 0;
}
8.
#include <stdio.h>
int main() {
int matrix[10][10];
int n;
printf("Enter the size of the square matrix (n x n): ");
scanf("%d", &n);
printf("Spiral Matrix:\n");
printSpiralMatrix(matrix, n);
return 0;
}
9.
#include <stdio.h>
#include <limits.h>
int main() {
int n;
int arr[n];
return 0;
}
10.
#include <stdio.h>
#include <string.h>
void reverseWord(char word[]) {
int len = strlen(word);
for (int i = 0; i < len / 2; i++) {
char temp = word[i];
word[i] = word[len - i - 1];
word[len - i - 1] = temp;
}
}
int main() {
char sentence[1000]; // Assuming the sentence is less than 1000 characters
printf("Enter a sentence: ");
fgets(sentence, sizeof(sentence), stdin);
printf("\n");
return 0;
}
int main() {
char sentence[1000];
return 0;
}
12.
#include <stdio.h>
#include <ctype.h>
int main() {
char input[1000];
return 0;
}
13.
#include <stdio.h>
#include <stdbool.h>
// If the complement is already in the hash table, a pair with the sum x
exists
if (hashTable[complement]) {
return true;
}
// Add the current element to the hash table
hashTable[A[i]] = true;
}
int main() {
int n, x;
int A[n];
if (hasPairWithSum(A, n, x)) {
printf("There exist two elements in the array whose sum is %d.\n", x);
} else {
printf("No such pair exists.\n");
}
return 0;
}
16.
#include <stdio.h>
if (count > n / 2) {
return candidate;
} else {
return -1; // No majority element exists
}
}
int main() {
int n;
int A[n];
if (majorityElement != -1) {
printf("The majority element is: %d\n", majorityElement);
} else {
printf("No majority element exists.\n");
}
return 0;
}
17. #include <stdio.h>
while (j < n) {
printf("%d ", arr2[j]);
j++;
}
printf("\n");
}
printf("\n");
}
int main() {
int m, n;
return 0;
}
18.
#include <stdio.h>
#include <math.h>
return sum / n;
}
int main() {
int n;
return 0;
}
19.
#include <stdio.h>
#include <ctype.h>
int main() {
char sentence[1000];
int wordCount = 0;
int alphabetCount = 0;
int i = 0;
char currentChar;
// Count alphabets
if (isalpha(currentChar)) {
alphabetCount++;
}
// Count the last word if the sentence doesn't end with a space
if (!isspace(sentence[i - 1]) && i > 0) {
wordCount++;
}
return 0;
}
20.
#include <stdio.h>
int main() {
int n;
printf("Sum Matrix:\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", sumMatrix[i][j]);
}
printf("\n");
}
printf("Difference Matrix:\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", diffMatrix[i][j]);
}
printf("\n");
}
return 0;
}
21.
#include <stdio.h>
return length;
}
int main() {
char inputString[100]; // You can change the size as needed
return 0;
}
22.
#include <stdio.h>
int main() {
int originalArray[] = {22, 16, 17, 18, 16};
int n = 5; // Number of elements in the original array
int position, newValue;
printf("Original Array: ");
for (int i = 0; i < n; i++) {
printf("%d ", originalArray[i]);
}
int newArray[n + 1]; // Create a new array with space for the new element
return 0;
}
23.
#include <stdio.h>
int isPrime(int num) {
if (num <= 1) {
return 0; // 0 and 1 are not prime numbers
}
int main() {
int n;
printf("Enter the value of n (greater than 20): ");
scanf("%d", &n);
if (n <= 20) {
printf("Please enter a value of n greater than 20.\n");
return 1;
}
int count = 0;
int number = 2; // Start with the first prime number
while (count < n) {
if (isPrime(number)) {
printf("%d ", number);
count++;
}
number++;
}
printf("\n");
return 0;
}
24.
#include <stdio.h>
return result;
}
int main() {
double base;
int exponent;
25.
#include <stdio.h>
if (minIndex == size) {
printf("No repeating elements found.\n");
} else {
printf("The first repeating element is %d at index %d.\n", arr[minIndex],
minIndex);
}
int main() {
int arr[] = {10, 5, 3, 4, 3, 5, 6};
int size = sizeof(arr) / sizeof(arr[0]);
findFirstRepeating(arr, size);
return 0;
}
26.
#include <stdio.h>
#include<stdlib.h>
return n + 1;
}
int main() {
int arr[] = {2, 3, 7, 6, 8, -1, -10, 15};
int n = sizeof(arr) / sizeof(arr[0]);
return 0;
}
27.
#include <stdio.h>
int main() {
int arr[] = {0, 1, 0, 1, 1, 0, 0, 1};
int n = sizeof(arr) / sizeof(arr[0]);
segregateZerosAndOnes(arr, n);
return 0;
}
28.
29.
#include <stdio.h>
return result;
}
int main() {
int arr[] = {4, 4, 2, 2, 3, 3, 5};
int n = sizeof(arr) / sizeof(arr[0]);
return 0;
}