SlidePub
Home
Categories
Login
Register
Home
General
Automata fix.pdf
Automata fix.pdf
sudarshanhacker
78 views
47 slides
Aug 12, 2022
Slide
1
of 47
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
About This Presentation
Automata Problems which is based on the basic problem solving methods.
Size:
295.59 KB
Language:
en
Added:
Aug 12, 2022
Slides:
47 pages
Slide Content
Slide 2
Sample Input: Sample Output:
1111112
3222222
3333334
5444444
5555556
Question 1
Write a C program to print the following pattern.
5
Slide 3
#include<stdio.h>
intmain()
{
inti,j,k,N;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
k=i%2;
for(j=1;j<8;j++)
{
if((j==7) && (k==1))
{
printf("%d",i+1);
break;
}
if((j==1) && (k==0))
{
printf("%d",i+1);
continue;;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
printf("%d",i);
}
printf("\n");
}
}
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Slide 4
5
1111112
3222222
3333334
5444444
5555556
OUTPUT
Slide 5
Sample Input: Sample Output:
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Question 2
Write a C program to print the following pattern.
5
Slide 6
#include<stdio.h>
#include<math.h>
intmain()
{
inti,j,n,size,left;
inttop,box[10][10],s;
scanf("%d",&size);
left=0,n=1,top=size-1;
s=ceil((double)size/2);
for(i=1;i<=s;left++,i++,top--)
{
for(j=left;j<=top;j++,n++)
{
box[left][j]=n;
}
for(j=left+1;j<=top;j++,n++)
{
box[j][top]=n;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
for(j=top-1;j>=left;j--,n++)
{
box[top][j]=n;
}
for(j=top-1;j>=left+1;j--,n++)
{
box[j][left]=n;
}
}
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
printf("%4d",box[i][j]);
}
printf("\n");
}
return 0;
}
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Slide 7
5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
OUTPUT
Slide 8
Sample Input: Sample Output:
H o
e l
l
e l
H o
Question 3
Write a C program to print the following pattern.
Hello
Slide 9
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k=1;
char s[10];
scanf("%s",s);
k=strlen(s);
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
if(i==j||k-j-1==i)
printf("%c",s[j]);
else
printf(" ");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 10
Hello
H o
e l
l
e l
H o
OUTPUT
Slide 11
Sample Input: Sample Output:
*
*
*****
*
*
Question 4
Write a C program to print the following pattern.
5
Slide 12
#include<stdio.h>
intmain()
{
inti,j,k;
scanf("%d",&k);
for(i=1;i<=k;i++)
{
for(j=1;j<=k;j++)
{
if( i==(k/2)+1 || j==(k/2 )+1)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 13
5
*
*
*****
*
*
OUTPUT
Slide 14
Sample Output:
ABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
Question 5
Write a C program to print the following pattern.
Slide 15
#include<stdio.h>
int main()
{
int i, j, k;
int blank = 0;
int lines = 6;
char symbol = 'A';
int temp;
int diff[7]={0,1,3,5,7,9,11};
k = 0;
for (i = lines; i >= 0; i --)
{
printf("\n");
symbol = 'A';
for (j = i; j >= 0; j --)
{
printf("%c ", symbol++);
}
blank = diff[k++];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 16
for (j = 0; j < blank; j++)
{
printf(" ");
}
symbol = 'F' -(blank / 2);
if (blank == 0)
{
temp = i -1;
}
else
{
temp = i;
}
for (j = 0; j <= temp; j++)
{
printf("%c ", symbol--);
}
}
return (0);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 17
A BC DE FG FE DC BA
A BC DE F FE DC BA
A BC DE E DC BA
A BC D DC BA
A BC C BA
A B BA
A A
OUTPUT
Slide 18
Sample Input: Sample Output:
1 2 3 6 9 8 7 4 5
Question 6
Write a C program to print the following pattern.
3
1 2 3
4 5 6
7 8 9
Slide 19
#include<stdio.h>
#define S 10
void print_spirally(inta[S][S], intn);
intmain()
{
intn;
scanf("%d ", &n);
inti, j, a[S][S];
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
scanf("%d", &a[i][j]);
}
}
print_spirally(a, n);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 20
void print_spirally(int a[S][S], int n)
{
int r_min= 0, c_min= 0;
int r_max= n-1, c_max= n-1;
int i;
while ((r_min<= r_max) && (c_min<= c_max))
{
for(i = c_min; (i <= c_max); i++)
printf("%d ", a[r_min][i]);
for(i = r_min+ 1; (i <= r_max); i++)
printf("%d ", a[i][c_max]);
for(i = c_max-1; (i >= c_min); i--)
printf("%d ", a[r_max][i]);
for(i = r_max-1; (i >= r_min+1); i--)
printf("%d ", a[i][c_min]);
r_min++; c_min++; r_max--; c_max--;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 21
3
1 2 3
4 5 6
7 8 9
1 2 3 6 9 8 7 4 5
OUTPUT
Slide 22
Sample Input: Sample Output:
*****
***
*
***
*****
Question 8
Write a C program to print the following pattern.
3
Slide 23
#include<stdio.h>
intmain()
{
intr,star,sp,n;
scanf("%d",&n);
for(r=n;r>=2;r--)
{
for(sp=1;sp<=n-r;sp++)
printf(" ");
for(star=1;star<=2*r-1;star++)
printf("*");
printf("\n");
}
for(r=1;r<=n;r++)
{
for(sp=1;sp<=n-r;sp++)
printf(" ");
for(star=1;star<=2*r-1;star++)
printf("*");
printf("\n");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 24
3
*****
***
*
***
*****
OUTPUT
Slide 25
Sample Input: Sample Output:
xxxx
x xx x
xx xx
xx xx
x xx x
xxxx
Question 9
Write a C program to print the following pattern.
xxxxxx
Slide 26
#include<stdio.h>
#include<string.h>
intmain()
{
inti,j,k=1;
char s[10];
scanf("%s",s);
k=strlen(s);
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
if(i==j||k-j-1==i)
printf(" ");
else
printf("%c",s[j]);
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 27
xxxxxx
xxxx
x xx x
xx xx
xx xx
x xx x
xxxx
OUTPUT
Slide 28
Sample Input: Sample Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
11 12 13 14 15
7 8 9 10
4 5 6
2 3
1
Question 10
Write a C program to print the following pattern.
5
Slide 29
#include <stdio.h>
int main()
{
int i,j,l=1,N;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
for(j=0;j<i;j++,l++)
{
printf("%3d",l);
}
printf("\n");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 30
l=l-N;;
for(i=N-1;i>=0;i--)
{
for(j=0;j<=i;j++)
{
printf("%3d",(l+j));
}
l=l-i;
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 31
Sample Input: Sample Output:
*****
****
***
**
*
Question 11
Write a C program to print the following pattern.
5
Slide 32
#include<stdio.h>
int main()
{
int n,r,c;
scanf("%d",&n);
for(r=n;r>=1;r--)
{
for(c=1;c<=r;c++)
{
printf("*");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 33
Sample Input: Sample Output:
*
**
***
****
*****
Question 12
Write a C program to print the following pattern.
5
Slide 34
#include<stdio.h>
int main()
{
int n,r,c;
scanf("%d",&n);
for(r=n;r>=1;r--)
{
for(c=1;c<=n;c++)
{
if(r<=c)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 35
Sample Input: Sample Output:
*****
****
***
**
*
Question 13
Write a C program to print the following pattern.
5
Slide 36
#include<stdio.h>
int main()
{
int n,r,c;
scanf("%d",&n);
for(r=1;r<=n;r++)
{
for(c=1;c<=n;c++)
{
if(r<=c)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 37
Sample Input: Sample Output:
1
2*2
3*3*3
4*4*4*4
5*5*5*5*5
4*4*4*4
3*3*3
2*2
1
Question 14
Write a C program to print the following pattern.
5
Slide 38
#include<stdio.h>
int main()
{
int n,r,c;
scanf("%d",&n);
for(r=1;r<=n-1;r++)
{
for(c=1;c<=r;c++)
{
if(r==c)
printf("%d",r);
else
printf("%d*",r);
}
printf("\n");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 39
for(r=n;r>=1;r--)
{
for(c=1;c<=r;c++)
{
if(r==c)
printf("%d",r);
else
printf("%d*",r);
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 40
Sample Input: Sample Output:
1
21
321
4321
54321
Question 15
Write a C program to print the following pattern.
5
Slide 41
#include<stdio.h>
int main()
{
int n,r,c;
scanf("%d",&n);
for(r=n;r>=1;r--)
{
for(c=1;c<=n;c++)
{
if(r<=c)
printf("%d",n-c+1);
else
printf(" ");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 42
Sample Input: Sample Output:
**
**
****
****
******
******
Question 16
Write a C program to print the following pattern.
6
Slide 43
#include<stdio.h>
int main()
{
int n,r,c;
scanf("%d",&n);
for(r=1;r<=n;r++)
{
for(c=1;c<=r;c++)
{
if(r%2==1 && r==c)
printf("**");
else
printf("*");
}
printf("\n");
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 44
Sample Input: Sample Output:
*
***
*****
*******
*********
*******
*****
***
*
Question 17
Write a C program to print the following pattern.
5
Slide 45
#include<stdio.h>
int main()
{
int r,star,sp,n;
scanf("%d",&n);
for(r=1;r<=n-1;r++)
{
for(sp=1;sp<=n-r;sp++)
printf(" ");
for(star=1;star<=2*r-1;star++)
printf("*");
printf("\n");
}
for(r=n;r>=1;r--)
{
for(sp=1;sp<=n-r;sp++)
printf(" ");
for(star=1;star<=2*r-1;star++)
printf("*");
printf("\n");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Slide 46
Sample Input: Sample Output:
*********
*******
*****
***
*
***
*****
*******
*********
Question 18
Write a C program to print the following pattern.
5
Slide 47
#include<stdio.h>
int main()
{
int r,star,sp,n;
scanf("%d",&n);
for(r=n;r>=2;r--)
{
for(sp=1;sp<=n-r;sp++)
printf(" ");
for(star=1;star<=2*r-1;star++)
printf("*");
printf("\n");
}
for(r=1;r<=n;r++)
{
for(sp=1;sp<=n-r;sp++)
printf(" ");
for(star=1;star<=2*r-1;star++)
printf("*");
printf("\n");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Tags
Categories
General
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
78
Slides
47
Age
1231 days
Related Slideshows
22
Pray For The Peace Of Jerusalem and You Will Prosper
RodolfoMoralesMarcuc
45 views
26
Don_t_Waste_Your_Life_God.....powerpoint
chalobrido8
53 views
31
VILLASUR_FACTORS_TO_CONSIDER_IN_PLATING_SALAD_10-13.pdf
JaiJai148317
44 views
14
Fertility awareness methods for women in the society
Isaiah47
43 views
35
Chapter 5 Arithmetic Functions Computer Organisation and Architecture
RitikSharma297999
45 views
5
syakira bhasa inggris (1) (1).pptx.......
ourcommunity56
44 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-47)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better