Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions HighestFreq.c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* C Program To Find the Highest Frequency Character in a String
*/
#include <stdio.h>
#include <string.h>

char string1[100], visited[100];
int count[100] = {0}, flag = 0;

void main()
{
int i, j = 0, k = 0, l, max, index;

printf("Enter a string : ");
scanf("%[^\n]s", string1);

l = strlen(string1);

for (i = 0; i < l; i++)
{
if (i == 0)
{
visited[j++] = string1[i];
count[j - 1]++;
}
else
{
for (k = 0; k < j; k++)
{
if (string1[i] == visited[k])
{
count[k]++;
flag = 1;
}
}
if (flag == 0)
{
visited[j++] = string1[i];
count[j - 1]++;
}
flag = 0;
}
}

for (i = 0; i < j; i++)
{
if ((i == 0) && (visited[i] != ' '))
{
max = count[i];
continue;
}
if ((max < count[i]) && (visited[i] != ' '))
{
max = count[i];
index = i;
}
}

printf("\nMax repeated character in the string = %c ", visited[index]);
printf("\nIt occurs %d times", count[index]);
}
110 changes: 110 additions & 0 deletions MatrixOperations.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <stdio.h>

void createDiagonalMatrix(int n) {
int matrix[n][n];

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = (i == j) ? 1 : 0;
}
}

printf("Diagonal Matrix:\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}

void createSquareMatrix(int size) {
int matrix[size][size];

for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
printf("Enter element at position (%d, %d): ", i, j);
scanf("%d", &matrix[i][j]);
}
}

printf("Square Matrix:\n");
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}

int sumMatrixElements(int rows, int cols) {
int matrix[rows][cols];
int totalSum = 0;

for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("Enter element at position (%d, %d): ", i, j);
scanf("%d", &matrix[i][j]);
totalSum += matrix[i][j];
}
}

printf("Custom Matrix:\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}

return totalSum;
}

int main() {
while (1) {
printf("Menu:\n");
printf("1: Enter numbers diagonally\n");
printf("2: Create a particular sized square matrix\n");
printf("3: Calculate sum of elements in matrix\n");
printf("4: Exit\n");

int choice;
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1: {
int size;
printf("Enter matrix size: ");
scanf("%d", &size);
createDiagonalMatrix(size);
break;
}
case 2: {
int size;
printf("Enter matrix size: ");
scanf("%d", &size);
createSquareMatrix(size);
break;
}
case 3: {
int rows, cols;
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &cols);
int totalSum = sumMatrixElements(rows, cols);
printf("Sum of elements in the matrix: %d\n", totalSum);
break;
}
case 4: {
printf("Exiting...\n");
return 0;
}
default:
printf("Invalid choice! Please select a valid option.\n");
}
}

return 0;
}
30 changes: 30 additions & 0 deletions string operation 1.c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<stdio.h>

// Funtion removing spaces from string
char * removeSpacesFromStr(char *string)
{
// non_space_count to keep the frequency of non space characters
int non_space_count = 0;

//Traverse a string and if it is non space character then, place it at index non_space_count
for (int i = 0; string[i] != '\0'; i++)
{
if (string[i] != ' ')
{
string[non_space_count] = string[i];
non_space_count++;//non_space_count incremented
}
}

//Finally placing final character at the string end
string[non_space_count] = '\0';
return string;
}

int main()
{
char string[] = "Edpresso: Dev -Shot";
printf("%s \n",string);
printf("%s",removeSpacesFromStr(string));
return 0;
}