-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e6161a
commit 67e3bda
Showing
9 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; | ||
} |