Skip to content

Commit fd6cb79

Browse files
authored
C Code
0 parents  commit fd6cb79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1659
-0
lines changed

2d array02.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int array[3][3],i,j,n,sum=0;
5+
float a,avg=0;
6+
for(i=0;i<3;i++){
7+
for(j=0;j<3;j++){
8+
printf("%d,%d = ",i,j);
9+
scanf("%d",&array[i][j]);
10+
sum += array[i][j];
11+
12+
}
13+
}
14+
a=i*j;
15+
avg=sum/a;
16+
printf("%d",sum);
17+
printf("Average = %f",avg);
18+
}
19+
20+

FrequencyOfChar.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
char a[100],b;
5+
printf("Enter any string=");
6+
gets(a);
7+
printf("enter any Character=");
8+
scanf("%c",&b);
9+
int i,count=0;
10+
for(i=0;a[i]!=NULL;i++)
11+
{
12+
if(a[i]==b)
13+
{
14+
count++;
15+
}
16+
17+
}
18+
printf("Frequency of [%c] is [%d] times ",b,count);
19+
}

LengthOfString.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<stdio.h> ///length of string
2+
int main()
3+
{
4+
int i=0,a,len=0;
5+
char ch[1000];
6+
gets(ch);
7+
while(ch[i]!='\0')
8+
{
9+
10+
i++;
11+
len++;
12+
}
13+
// a=strlen(ch);
14+
// printf("%d",a);
15+
printf("%d",len);
16+
}

Short String.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
int main ()
5+
{
6+
char string[100];
7+
printf("\n\t Enter the string : ");
8+
scanf("%s",string);
9+
char temp;
10+
int i, j;
11+
int n = strlen(string);
12+
for (i = 0; i < n-1; i++) {
13+
for (j = i+1; j < n; j++) {
14+
if (string[i] > string[j]) {
15+
temp = string[i];
16+
string[i] = string[j];
17+
string[j] = temp;
18+
}
19+
}
20+
}
21+
22+
printf("The sorted string is : %s", string);
23+
return 0;
24+
}

X,N,H.c

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int i,j,n;
5+
scanf("%d",&n);
6+
7+
8+
for(i=1;i<=n;i++) //X
9+
{
10+
for(j=1;j<=n;j++)
11+
{
12+
if(i==j || (i+j)==(n+1))
13+
/*N-if(j==1 || j==n || (i+j)==(n+1))
14+
H-if(j==1 || j==n || i==(n+1)/2)*/
15+
{
16+
printf("*");
17+
}
18+
else
19+
printf(" ");
20+
}
21+
printf("\n");
22+
}
23+
printf("\n\n");
24+
25+
26+
for(i=1;i<=n;i++)//N
27+
{
28+
for(j=n;j>=1;j--)
29+
{
30+
if(j==1 || j==n || (i+j)==(n+1))
31+
{
32+
printf("*");
33+
}
34+
else
35+
printf(" ");
36+
}
37+
printf("\n");
38+
}
39+
printf("\n\n");
40+
41+
42+
for(i=1;i<=n;i++)//H
43+
{
44+
for(j=1;j<=n;j++)
45+
{
46+
if(j==1 || j==n || i==(n+1)/2)
47+
{
48+
printf("H");
49+
}
50+
else
51+
printf(" ");
52+
}
53+
printf("\n");
54+
}
55+
printf("\n\n");
56+
57+
58+
for(i=1;i<=n;i++)//A
59+
{
60+
for(j=1;j<=n;j++)
61+
{
62+
if(i==j || (i+j)==(n+1))
63+
{
64+
printf("*");
65+
}
66+
else
67+
printf(" ");
68+
}
69+
printf("\n");
70+
}
71+
printf("\n\n");
72+
73+
74+
for(i=1;i<=n;i++)//M
75+
{
76+
for(j=1;j<=n;j++)
77+
{
78+
if(i==j || (i+j)==(n+1))
79+
{
80+
printf("*");
81+
}
82+
else
83+
printf(" ");
84+
}
85+
printf("\n");
86+
}
87+
}

amicableNumber.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int i;
5+
int num,sum=0;
6+
scanf("%d",&num);
7+
for(i=1;i<=num;i++)
8+
{
9+
if(num%i==0){
10+
printf("%d\n",i);
11+
sum= sum+i;
12+
}
13+
}
14+
int total=sum-num;
15+
printf("\n\n%d",total);
16+
}

array position.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<stdio.h>
2+
#include<limits.h>
3+
int main()
4+
{
5+
int i,n,input,min=INT_MAX,j;
6+
scanf("%d",&n);
7+
for(i=0 ; i<=n ; i++){
8+
scanf("%d",&input);
9+
if(input>min){
10+
min=input;
11+
}
12+
}
13+
printf("%d",min);
14+
15+
min=0;
16+
for(j=0 ; j<n ; j++)
17+
{
18+
if(array[j] == min)
19+
{
20+
min=1;
21+
break;
22+
}
23+
}
24+
if(min==1)
25+
{
26+
printf("%d is found at position %d",min,j+1);
27+
}
28+
else
29+
printf("%d",min);
30+
return 0;
31+
}

asci value.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
char c;
5+
printf("Enter a character :");
6+
scanf("%c",&c);
7+
printf("ASCII value of %c=%d",c,c);
8+
return 0;
9+
}

basicOfPattern.c

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int i,j,n;
5+
scanf("%d",&n);
6+
for(i=1;i<=n;i++)
7+
{
8+
for(j=1;j<=n;j++)
9+
{
10+
printf("%d",j);
11+
}
12+
printf("\n");
13+
}
14+
}

blankStar.c

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int n,i,j,k;
5+
scanf("%d", &n);
6+
7+
for(i=1;i<=n;i++)
8+
{
9+
for(j=1;j<=n;j++)
10+
{
11+
printf(" "); // blank space
12+
}
13+
14+
for(k=1;k<=n;k++)
15+
{
16+
printf("*");
17+
}
18+
19+
printf("\n");
20+
}
21+
22+
return 0;
23+
}

check alphabet.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
char ch;
5+
printf("Enter any character :");
6+
scanf("%c",&ch);
7+
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
8+
printf("%c is alphabet",ch);
9+
else
10+
printf("%c is not alphabet",ch);
11+
return 0;
12+
}

check character.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
char ch;
5+
printf("C program to check whether a character is alphabet, digit or special character.\n\n");
6+
printf("Enter any character :");
7+
scanf("%c",&ch);
8+
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
9+
printf("%c is alphabet",ch);
10+
else if(ch>='0' && ch<='9')
11+
printf("%c is digit",ch);
12+
else
13+
printf("%c is special character",ch);
14+
return 0;
15+
}

check even odd.c

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int x,y,z; //x,y are numbers
5+
int p,q,r; //for sum,sub,mul
6+
int a,b,i; //for digit.a=result and b=mod
7+
float s,t; //for div,mod
8+
scanf("%d%d",&x,&y); /*variable declaration*/
9+
printf("sum=%d\n",p=x+y);
10+
printf("sub=%d\n",q=x-y);
11+
printf("mul=%d\n",r=x*y);
12+
printf("div=%f\n",s=x/y);
13+
printf("mod=%f\n",t=x%y);
14+
if(x>y)
15+
{
16+
printf("%d>%d\n",x,y);
17+
}
18+
if(x<y)
19+
{
20+
printf("%d<%d\n",x,y);
21+
}
22+
if(x==y)
23+
{
24+
printf("x and y are equal\n");
25+
}
26+
if(x%2==0)
27+
{
28+
printf("%d is even\n",x);
29+
}
30+
else
31+
{
32+
printf("%d is odd\n",x);
33+
}
34+
if(y%2==0)
35+
{
36+
printf("%d is even\n",y);
37+
}
38+
else
39+
{
40+
printf("%d is odd\n",y);
41+
}
42+
return 0;
43+
}

color code.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
int main() {
5+
char color_name[20];
6+
printf("Enter a color name: ");
7+
scanf("%s", color_name);
8+
9+
if (strcmp(color_name, "red") == 0) {
10+
printf("Color code: #ff0000\n");
11+
} else if (strcmp(color_name, "green") == 0) {
12+
printf("Color code: #00ff00\n");
13+
} else if (strcmp(color_name, "blue") == 0) {
14+
printf("Color code: #0000ff\n");
15+
} else if (strcmp(color_name, "yellow") == 0) {
16+
printf("Color code: #ffff00\n");
17+
} else if (strcmp(color_name, "purple") == 0) {
18+
printf("Color code: #800080\n");
19+
} else {
20+
printf("Unknown color\n");
21+
}
22+
23+
return 0;
24+
}

concatenate.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<stdio.h> ///concatenate
2+
int main()
3+
{
4+
int i=0,j=0,len=0;
5+
char line1[1000];
6+
char line2[1000];
7+
gets(line1);
8+
gets(line2);
9+
// strcat(line1,line2);
10+
// printf("%s",line1);
11+
while(line1[i]!='\0')
12+
{
13+
i++;
14+
len++;
15+
}
16+
// printf("%d",i);
17+
while(line2[j]!='\0')
18+
{
19+
line1[len+j]=line2[j];
20+
j++;
21+
}
22+
printf("%s",line1);
23+
24+
}

0 commit comments

Comments
 (0)