Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
susmita413 authored Apr 26, 2024
1 parent 8e6161a commit 67e3bda
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 0 deletions.
15 changes: 15 additions & 0 deletions module 11_stringOperation/a_copyString.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copy from ONE string to ANOTHER STRING
//
#include<stdio.h>
#include<string.h>
int main(){
char a[100], b[100];
scanf("%s %s",&a,&b); // space will not accept in any string
// for(int i=0; i<=strlen(b); i++){
// a[i] = b[i] ; // COPY from STRING-b to STRING-a // NULL CHARACTER also copied
// }

strcpy(a,b); // SAME WORK WITH FUNCTION
printf("%s %s\n",a,b) ;
return 0 ;
}
19 changes: 19 additions & 0 deletions module 11_stringOperation/b_Lex__strcmp_.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Lexicographically compare WITH "strcmp()" FUNCTION


#include<stdio.h>
#include<string.h>

int main(){
char a[100], b[100];
scanf("%s %s",a,b);

int ans = strcmp(a,b);

if(ans<0) printf("A is SMALLER"); // most of time ans=-1
else if(ans==0) printf("SAME STRING");
else if(ans>0) printf("B is SMALLER"); // most of time ans=1


return 0 ;
}
33 changes: 33 additions & 0 deletions module 11_stringOperation/b_Lexicographically_compare.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Lexicographically compare

#include<stdio.h>
#include<string.h>
int main(){
char a[100], b[100];
scanf("%s %s",a,b);
int i=0 ;
while(1){
if(a[i]=='\0' && b[i]=='\0'){ // FOR NULL CHECK
printf("SAME STRING\n"); break ;
}
else if(a[i]=='\0') {
printf("A is smaller\n"); break;
}
else if(b[i]=='\0'){
printf("B is smaller\n"); break ;
}

if(a[i]== b[i]){ // FOR LETTER CHECK
i++ ;
}
else if(a[i]>b[i]){
printf("B is smaller\n"); break ;
}
else {
printf("A is smaller\n"); break ;
}


}
return 0 ;
}
20 changes: 20 additions & 0 deletions module 11_stringOperation/c_string_concat_3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// STRING CONCATENATION only 3 character // a= apple , b= orange

// after concat, a= appleora

#include<stdio.h>
#include <string.h>

int main(){
char a[200], b[100];
scanf("%s %s",&a,&b);

int k= strlen(a);
for(int i=0; i<=2; i++){
a[k] = b[i];
k++ ;
}
a[k]= '\0';
printf("%s %s", a,b);
return 0 ;
}
14 changes: 14 additions & 0 deletions module 11_stringOperation/c_string_concat_FUNC.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// STRING CONCATENATION // a= apple , b= orange
// after concat, a= appleorange

#include<stdio.h>
#include <string.h>

int main(){
char a[200], b[100];
scanf("%s %s",&a,&b);
strcat(a,b);

printf("%s %s", a,b);
return 0 ;
}
19 changes: 19 additions & 0 deletions module 11_stringOperation/c_string_concatenation.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// STRING CONCATENATION // a= apple , b= orange
// after concat, a= appleorange

#include<stdio.h>
#include <string.h>

int main(){
char a[200], b[100];
scanf("%s %s",&a,&b);

int k= strlen(a);
for(int i=0; i<=strlen(b); i++){
a[k] = b[i];
k++ ;
}

printf("%s %s", a,b);
return 0 ;
}
26 changes: 26 additions & 0 deletions module 11_stringOperation/d_Counting_array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// COUNTING ARRAY / FREQUENCY ARRAY // ** INTEGER
// count value 0 to 6 from an ARRAY
// MAIN ARRAY's values start from 0, end with 6.

#include<stdio.h>

int main(){
int n;
scanf("%d",&n);
int ar[n];
for(int i=0; i<n; i++){
scanf("%d",&ar[i]);
}

int cnt[7]={0} ;
for(int i=0; i<n; i++){
int val= ar[i];
cnt[val]= cnt[val]+1 ; // cnt[val]++
}

for(int i=0; i<7; i++){
printf(" %d = %d times\n",i, cnt[i]);
}

return 0 ;
}
25 changes: 25 additions & 0 deletions module 11_stringOperation/e_Cunting_Array_Char.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// COUNTING ARRAY / FREQUENCY ARRAY
// count character 'a' to 'z' from an ARRAY
// MAIN ARRAY's values start from 0, end with 27.
//*** ALPHABETICALLY PRINT

#include<stdio.h>
#include<string.h>

int main(){
char ar[100];
scanf("%s",&ar);

int cnt[26]={0} ;
for(int i=0; i<strlen(ar); i++){
int val= ar[i]-'a' ;
cnt[val]= cnt[val]+1 ; // cnt[val]++
}

for(int i=0; i<26; i++){
if(cnt[i] != 0) // ALPHABETICALLY PRINT
printf("%c = %d times\n",i+'a', cnt[i]);
}

return 0 ;
}
27 changes: 27 additions & 0 deletions module 11_stringOperation/e_Cunting_Array_Char01.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// COUNTING ARRAY / FREQUENCY ARRAY
// count character 'a' to 'z' from an ARRAY
// MAIN ARRAY's values start from 0, end with 27.
//** string CHARECTER WISE PRINT

#include<stdio.h>
#include<string.h>

int main(){
char ar[100];
scanf("%s",&ar);

int cnt[26]={0} ;
for(int i=0; i<strlen(ar); i++){
int val= ar[i]-'a' ;
cnt[val]= cnt[val]+1 ; // cnt[val]++
}

for(int i=0; i<strlen(ar); i++){ //string CHARECTER WISE PRINT
int val = ar[i] - 'a' ;
if(cnt[val] != 0)
printf("%c = %d times\n",ar[i], cnt[val]);
cnt[val]= 0 ;
}

return 0 ;
}

0 comments on commit 67e3bda

Please sign in to comment.