Skip to content

Commit 4cb5385

Browse files
committed
added more codes
1 parent 090262b commit 4cb5385

File tree

5 files changed

+182
-0
lines changed

5 files changed

+182
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//find the most frequent character from a string
2+
3+
#include<stdio.h>
4+
#include<stdlib.h>
5+
#include<string.h>
6+
#define length 10
7+
int main()
8+
{
9+
char *word = (char*)malloc(length*sizeof(char));
10+
printf("enter word\n");
11+
scanf("%s",word);
12+
13+
int frequency = 0, count =0;
14+
char freqChar;
15+
int wordlength = strlen(word);
16+
for(int i=0;i<wordlength;i++)
17+
{
18+
count = 0;
19+
for(int j=0;j<wordlength;j++)
20+
{
21+
if(i!=j && word[i]==word[j])
22+
{
23+
count++;
24+
}
25+
if(count > frequency)
26+
{
27+
freqChar = word[i];
28+
frequency = count;
29+
}
30+
}
31+
}
32+
printf("frequent :%c",freqChar);
33+
free(word);
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//get data and sort based on user input
2+
3+
#include<stdio.h>
4+
#include<stdlib.h>
5+
6+
#define max 20
7+
static int len = 0;
8+
int data;
9+
void sortArray(int arr[],int option)
10+
{
11+
for(int i=0;i<len;i++)
12+
{
13+
for(int j=i;j<len;j++)
14+
{
15+
switch(option)
16+
{
17+
case 1:
18+
if(arr[i]>arr[j])
19+
{
20+
arr[i] = arr[i]+arr[j];
21+
arr[j] = arr[i]-arr[j];
22+
arr[i] = arr[i]-arr[j];
23+
}
24+
break;
25+
case 2:
26+
if(arr[i]<arr[j])
27+
{
28+
arr[i] = arr[i]+arr[j];
29+
arr[j] = arr[i]-arr[j];
30+
arr[i] = arr[i]-arr[j];
31+
}
32+
break;
33+
}
34+
}
35+
}
36+
}
37+
void setArray(int arr[])
38+
{
39+
printf("Enter data..add zero to close\n");
40+
scanf("%d",&data);
41+
if(data!=0)
42+
{
43+
arr[len]= data;
44+
len++;
45+
setArray(arr);
46+
}
47+
}
48+
void getArray(int arr[])
49+
{
50+
for(int i=0;i<len;i++)
51+
{
52+
printf("%d ",arr[i]);
53+
}
54+
printf("\n");
55+
}
56+
int main()
57+
{
58+
int option;
59+
int *arr = (int*)malloc(max*sizeof(int));
60+
setArray(arr);
61+
getArray(arr);
62+
printf("Array created\n1.Accending order\n2.Decending order\n");
63+
scanf("%d",&option);
64+
switch (option)
65+
{
66+
case 1:
67+
sortArray(arr,option);
68+
break;
69+
case 2:
70+
sortArray(arr,option);
71+
break;
72+
default:
73+
break;
74+
}
75+
getArray(arr);
76+
free(arr);
77+
}

functions/arkamans_functions.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//arkamans_functions
2+
//for theory - https://www.geeksforgeeks.org/ackermann-function/
3+
4+
#include<stdio.h>
5+
int arkamansFun(int m,int n)
6+
{
7+
if(m == 0)
8+
{
9+
return n+1;
10+
}
11+
if(m > 0 && n == 0)
12+
{
13+
return arkamansFun(m-1,1);
14+
}
15+
if(m > 0 && n > 0)
16+
{
17+
return arkamansFun(m-1,arkamansFun(m,n-1));
18+
}
19+
}
20+
int main()
21+
{
22+
int m,n,res;
23+
printf("enter m and n\n");
24+
scanf("%d %d",&m,&n);
25+
if(m >= 0 && n >= 0)
26+
{
27+
res = arkamansFun(m,n);
28+
printf("A(%d,%d) = %d",m,n,res);
29+
}
30+
else
31+
printf("m and n should be non negative no\n");
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//basics of macros
2+
3+
#include<stdio.h>
4+
typedef unsigned int uint8;
5+
#define FLT_L_HS_A ((uint8)0x80) //hexadecimal value typecasted into unsigned int and store it into FLT_L_HS_A
6+
#define FLT_L_HS_B ((float)0x80)
7+
int main()
8+
{
9+
printf("%d\n",FLT_L_HS_A);
10+
printf("%f\n",FLT_L_HS_B);
11+
printf("%x\n",0x80);
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//static storage class
2+
//static global means we can't use that variable outside the pgrm with extern command
3+
//for a normal global varialbe we can access other pgrm but by using static we can't
4+
5+
#include<stdio.h>
6+
static int j = 0; //static global variable
7+
void globalFunctionCall(void)
8+
{
9+
j++;
10+
printf("%d ",j);
11+
if(j<5)
12+
globalFunctionCall();
13+
}
14+
void staticFunctionCall(void)
15+
{
16+
static int i = 0;
17+
i++;
18+
printf("%d ",i);
19+
if(i<5)
20+
staticFunctionCall();
21+
}
22+
int main()
23+
{
24+
staticFunctionCall();
25+
printf("\n");
26+
globalFunctionCall();
27+
}

0 commit comments

Comments
 (0)