Skip to content

Commit b66d9a9

Browse files
Add files via upload
1 parent bf47b93 commit b66d9a9

30 files changed

+292
-0
lines changed
40.5 KB
Binary file not shown.

Recursion/Largest-array-recursion.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<stdio.h>
2+
int large(int []);
3+
int N,i,max;
4+
void main(){
5+
int arr[20];
6+
printf("enter number of elements");
7+
scanf("%d",&N);
8+
for(i = 0;i<N;i++){
9+
printf("number %d:",i+1);
10+
scanf("%d",&arr[i]);
11+
}
12+
max = large(arr);
13+
printf("the largest number is %d",max);
14+
}
15+
int large(int arr[]){
16+
int static i=0;
17+
if(i<N){
18+
if(max < arr[i])
19+
max=arr[i];
20+
i++;
21+
large(arr);
22+
}
23+
return max;
24+
}
40.4 KB
Binary file not shown.

Recursion/Recursion-factorial.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<stdio.h>
2+
int fact(int n){
3+
if(n==0)
4+
return 1;
5+
else
6+
return n*fact(n-1);
7+
}
8+
void main(){
9+
int n;
10+
printf("enter number");
11+
scanf("%d",&n);
12+
printf("Factorial is %d",fact(n));
13+
}
Binary file not shown.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<stdio.h>
2+
3+
// For star Pattern Printing
4+
5+
/*
6+
7+
For r=6
8+
9+
* * * * * *
10+
* * * * *
11+
* * * *
12+
* * *
13+
* *
14+
*
15+
16+
*/
17+
18+
void main(){
19+
20+
int r,i,j,s;
21+
22+
printf("Enter number of rows: ");
23+
scanf("%d",&r);
24+
25+
for(i=1;i<=r;i++){
26+
for(s=1;s<=i;s++){
27+
printf(" ");
28+
}
29+
30+
for(j=i;j<=r;j++){
31+
printf("* ");
32+
}
33+
printf("\n");
34+
}
35+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<stdio.h>
2+
3+
// For star Pattern Printing
4+
5+
/*
6+
7+
For r=6
8+
9+
******
10+
*****
11+
****
12+
***
13+
**
14+
*
15+
*/
16+
17+
18+
void main(){
19+
int r,i,j,s;
20+
printf("Enter number of rows: ");
21+
scanf("%d",&r);
22+
for(i=0;i<=r;i++){
23+
for(s=0;s<=i-1;s++){
24+
printf(" ");
25+
}
26+
for(j=i;j<=r;j++){
27+
printf("*");
28+
}
29+
if(i<r){printf("\n");}
30+
}
31+
}
Binary file not shown.
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<stdio.h>
2+
3+
// For star Pattern Printing
4+
5+
/*
6+
7+
For r=6
8+
9+
*
10+
* *
11+
* * *
12+
* * * *
13+
* * * * *
14+
* * * * * *
15+
16+
*/
17+
void main(){
18+
19+
int r,i,j;
20+
21+
printf("Enter number of rows: ");
22+
scanf("%d",&r);
23+
24+
for(i=1;i<=r;i++){
25+
for(j=1;j<=i;j++){
26+
27+
printf("* ");
28+
}
29+
printf("\n");
30+
31+
}
32+
}
33+
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<stdio.h>
2+
3+
// For star Pattern Printing
4+
5+
/*
6+
7+
For r=6
8+
9+
*
10+
**
11+
***
12+
****
13+
*****
14+
******
15+
16+
*/
17+
void main(){
18+
int r,i,j,s;
19+
printf("Enter number of rows: ");
20+
scanf("%d",&r);printf("Pattern is:");
21+
for(i=0;i<=r;i++){
22+
for(s=1;s<i;s++){
23+
printf(" ");
24+
}
25+
for(j=0;j<i;j++){
26+
printf("*");
27+
}
28+
if(i<r){printf("\n");}
29+
}
30+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
void main(){
4+
char str[100],i;
5+
printf("Enter a string:\n");
6+
scanf("%s",str);
7+
i = strlen(str);
8+
printf("Length of string is %d",i);
9+
}
Binary file not shown.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
void main(){
4+
char s1[100], s2[100],i,j;
5+
printf("Enter string s1:");
6+
gets(s1);
7+
printf("Enter string s2:");
8+
scanf("%s",s2);
9+
i = strcmp(s1,s2);
10+
if(i ==0){
11+
printf("str1 equal to str2");
12+
}
13+
else if (i > 0){
14+
printf("str2 is less than str1");
15+
}
16+
else
17+
{
18+
printf("str1 is less than str2");
19+
}
20+
}
Binary file not shown.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
void main(){
4+
char s1[100], s2[100],i;
5+
printf("Enter string s1:");
6+
fgets(s1, sizeof(s1), stdin);
7+
strcpy(s2, s1);
8+
printf("s2 : %s",s2);
9+
}
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
void main(){
4+
char str[56];
5+
char *s;
6+
int i,len,temp;
7+
printf("Enter string:");
8+
scanf("%s",str);
9+
printf("The length of string is: %d\n",strlen(str));
10+
printf("The reverse of string is: %s\n",strrev(str));
11+
s=strrev(str);
12+
len=strlen(str);
13+
for(i=0;i<len;i++){
14+
if(str[i]!=s[i]){
15+
temp=1;
16+
}
17+
else{
18+
temp=0;
19+
}
20+
}
21+
if(temp==0){
22+
printf("String %s is palindrome.",str);
23+
}
24+
else{
25+
printf("String %s is not palindrome.",str);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
void main(){
4+
char str[56];
5+
printf("Enter string:");
6+
scanf("%s",str);
7+
printf("The length of string is: %d\n",strlen(str));
8+
printf("The reverse of string is: %s\n",strrev(str));
9+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<stdio.h>
2+
void main(){
3+
char s1[100], s2[100],i,j;
4+
printf("Enter string s1:");
5+
gets(s1);
6+
printf("Enter string s2:");
7+
scanf("%s",s2);
8+
int str_compare(char s1[],char s2[]){
9+
while(s1[i] == s2[i]){
10+
if (s1[i] =='\0'|| s2[i] == '\0')
11+
i++;
12+
}
13+
if(s1[i] == s2[i])
14+
printf("str1 equal to str2");
15+
else if (s1[i] <s2[i])
16+
printf("str1 is greater than str2");
17+
else
18+
printf("str2 is greater than str1");
19+
}
20+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include<stdio.h>
2+
void main(){
3+
char s1[100], s2[100],i,j;
4+
printf("Enter string s1:");
5+
scanf("%s",s1);
6+
printf("Enter string s2:");
7+
scanf("%s",s2);
8+
for(i=0; s1[i]!='\0'; ++i);
9+
for(j=0;s2[j]!='\0'; ++j, ++i){
10+
s1[i] = s2[j];
11+
}
12+
s1[i] = '\0';
13+
printf("\noutput:%s",s1);
14+
}
Binary file not shown.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include<stdio.h>
2+
void main(){
3+
char s1[100], s2[100],i;
4+
printf("Enter string s1:");
5+
fgets(s1,sizeof(s1),stdin);
6+
for (i=0; s1[i] !='0';++i){
7+
s2[i] = s1[i];
8+
}
9+
printf("string s2 :%s",s2);
10+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include<stdio.h>
2+
void main(){
3+
char str[100],i;
4+
printf("Enter a string:\n");
5+
scanf("%s",str);
6+
for(i = 0; str[i] != '\0'; ++i);
7+
printf("Length of string is %d",i);
8+
}

0 commit comments

Comments
 (0)