Skip to content

Commit 3cc4b75

Browse files
committed
added new files on 21-05-2021
1 parent 0e12e9c commit 3cc4b75

File tree

5 files changed

+307
-0
lines changed

5 files changed

+307
-0
lines changed

bestlogicpattern.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
int MAX(int a,int b)
4+
{
5+
if(a>b)
6+
return a;
7+
else if(b>a)
8+
return b;
9+
else
10+
return a;
11+
}
12+
int main()
13+
{
14+
printf("enter the number: ");
15+
int n;
16+
scanf("%d",&n);
17+
int l=2*n-1;
18+
for(int i=-n+1;i<n;i++)
19+
{
20+
for(int j=-n+1;j<n;j++)
21+
printf("%d ",MAX(abs(i),abs(j))+1);
22+
printf("\n");
23+
}
24+
}

clone expansion.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
void print(int **s,int i,int columns,int degree)
5+
{
6+
int j,x;
7+
for(j=0;j<columns;j++)
8+
{
9+
x=0;
10+
if(columns%2!=0)
11+
if(j!=columns/2) {
12+
while(x<=degree) {
13+
printf("%d ",s[i][j]);
14+
x++; }
15+
}
16+
else
17+
printf("%d ",s[i][j]);
18+
else
19+
{
20+
if(j==columns/2 || j==columns/2-1)
21+
printf("%d ",s[i][j]);
22+
else
23+
while(x<=degree) {
24+
printf("%d ",s[i][j]);
25+
x++; }
26+
}
27+
28+
}
29+
}
30+
31+
int main()
32+
{
33+
int rows,columns,i,j,degree,y,**s;
34+
printf("Enter rows and columns : ");
35+
scanf("%d %d",&rows,&columns);
36+
s=(int**)malloc(sizeof(int)*rows);
37+
for(i=0;i<rows;i++)
38+
s[i]=(int*)malloc(sizeof(int)*columns);
39+
printf("Enter array :-\n");
40+
for(i=0;i<rows;i++)
41+
{
42+
for(j=0;j<columns;j++)
43+
scanf("%d",&s[i][j]);
44+
}
45+
printf("Enter expansion degree : ");
46+
scanf("%d",&degree);
47+
printf("\n");
48+
for(i=0;i<rows;i++)
49+
{
50+
y=0;
51+
if(rows%2!=0)
52+
{
53+
if(i!=rows/2)
54+
while(y<=degree)
55+
{
56+
print(s,i,columns,degree);
57+
printf("\n");
58+
y++;
59+
}
60+
else
61+
{
62+
print(s,i,columns,degree);
63+
printf("\n");
64+
}
65+
}
66+
else
67+
{
68+
if(i==rows/2 || i==rows/2-1)
69+
{
70+
print(s,i,columns,degree);
71+
printf("\n");
72+
}
73+
else
74+
{
75+
while(y<=degree)
76+
{
77+
print(s,i,columns,degree);
78+
printf("\n");
79+
y++;
80+
}
81+
}
82+
}
83+
}
84+
return 0;
85+
}

reversing a number.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<stdio.h>
2+
#include<math.h>
3+
int main()
4+
{
5+
int k=0;
6+
int a=0,b=0,c=0,d=0,i=0;
7+
printf("enter a number: \n");
8+
scanf("%d",&a);
9+
while(a>0)
10+
{
11+
if(i==0)
12+
b=a%10;
13+
else if(a<10)
14+
c=a;
15+
else
16+
d=d*10+(a%10);
17+
a=a/10;
18+
i++;
19+
}
20+
for(int i=d;i>0;i/=10)
21+
k=k*10+i%10;
22+
k=k*10+c;
23+
float x=b*pow(10,(i-1))+k;
24+
printf("the number is: %f",x);
25+
}
26+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
struct stack
4+
{
5+
int top;
6+
int capacity;
7+
int *a;
8+
};
9+
struct stack *newstack=(struct stack*)malloc(sizeof(struct stack));
10+
void push()
11+
{
12+
int data;
13+
if(newstack->top == newstack->capacity-1)
14+
printf("overflow");
15+
else
16+
{
17+
printf("enter the data: ");
18+
scanf("%d",&data);
19+
newstack->a[++newstack->top]=data;
20+
}
21+
}
22+
void pop()
23+
{
24+
if(newstack->top==-1)
25+
printf("the stack is already empty");
26+
else
27+
{
28+
newstack->a[newstack->top--];
29+
}
30+
}
31+
void display()
32+
{
33+
if(newstack->top==-1)
34+
printf("nothing to print");
35+
else
36+
{
37+
for(int i=newstack->top;i>=0;i--)
38+
printf("%d ",newstack->a[i]);
39+
}
40+
}
41+
int main()
42+
{
43+
newstack->top=-1;
44+
newstack->a=(int*)malloc(newstack->capacity*sizeof(int));
45+
int capacity=100;
46+
newstack->capacity=capacity;
47+
bool flag=true;
48+
while(flag)
49+
{
50+
printf("----------------------------------------\n");
51+
printf("enter 1 to push the element in stack \n enter 2 to pop the element from stack \n enter 3 to display the entire stack \n enter 4 to exit \n");
52+
printf("enter your choice: ");
53+
int n;
54+
scanf("%d",&n);
55+
switch(n)
56+
{
57+
case 1: push();
58+
break;
59+
case 2: pop();
60+
break;
61+
case 3: display();
62+
printf("\n");
63+
break;
64+
case 4: flag=false;
65+
break;
66+
default: printf("invalid choice");
67+
}
68+
}
69+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
struct node
4+
{
5+
int data;
6+
struct node *link;
7+
};
8+
struct node *head=NULL;
9+
void push ()
10+
{
11+
int data;
12+
struct node *temp =(struct node*)malloc(sizeof(struct node));
13+
printf("Enter the data: ");
14+
scanf("%d",&data);
15+
if(head==NULL)
16+
{
17+
temp->data = data;
18+
temp -> link = NULL;
19+
head=temp;
20+
}
21+
else
22+
{
23+
temp->data = data;
24+
temp->link = head;
25+
head=temp;
26+
27+
}
28+
}
29+
void pop()
30+
{
31+
int item;
32+
struct node *temp;
33+
if (head == NULL)
34+
{
35+
printf("Stack is already empty");
36+
}
37+
else
38+
{
39+
item = head->data;
40+
temp = head;
41+
head = head->link;
42+
free(temp);
43+
printf("data popped");
44+
45+
}
46+
}
47+
void show()
48+
{
49+
struct node *temp;
50+
temp=head;
51+
if(temp == NULL)
52+
{
53+
printf("Stack is empty\n");
54+
}
55+
else
56+
{
57+
while(temp!=NULL)
58+
{
59+
printf("%d\n",temp->data);
60+
temp = temp->link;
61+
}
62+
}
63+
}
64+
int main ()
65+
{
66+
bool flag=true;
67+
while(flag != false)
68+
{
69+
int n;
70+
printf("\n----------------------------------------------");
71+
printf("\nEneter 1 to push\nEnter 2 to pop\nEnter 3 to show the stack\nEnter 4 to Exit");
72+
printf("\n Enter your choice \n");
73+
scanf("%d",&n);
74+
switch(n)
75+
{
76+
case 1:
77+
{
78+
push();
79+
break;
80+
}
81+
case 2:
82+
{
83+
pop();
84+
break;
85+
}
86+
case 3:
87+
{
88+
show();
89+
break;
90+
}
91+
case 4:
92+
{
93+
printf("Exiting");
94+
flag=false;
95+
break;
96+
}
97+
default:
98+
{
99+
printf("Invalid choice");
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)