First category
#include<stdio.h
int main()
{
int n, k;
int i;
scanf("%d", &n);
//i Is the number of rows
for (i = 1; i <= n; i++)
{
//k Represents the number of spaces , Because the initial number is in the middle , So the output space should be the input number n- Number of rows i
for (k = 1; k <=n-i; k++)
{
printf(" ");
}
//j Represents the number of outputs with the same number , Obviously j So 2i-1 Ascending downward , And each line ,j++, until j greater than 2*i-1, Jump out of loop
for (int j=0;j<2*i-1;j++)
{
// The final output is (i-1)%10 Because the maximum number is 9, When entered n greater than 9 Hour , take n right 10 Remainder of
printf("%d", (i-1)%10);
}
printf("\n");
}
return 0;
}
Second category
#include<stdio.h>
int main()
{
int i, a, b, c;
scanf("%d", &a);
//b Number of rows representing output ;
for (b = 1; b <= a; b++)
{
//i Represents the number of spaces output per line
for (i = 1; i <= a - b; i++)printf(" ");
//c Represents the number of outputs per line ,(b-1) Number representing the first item ,(((b - 1) % 10) + c - 1) % 10); Represents the maximum number of outputs , And decrease in turn on both sides of the maximum number
for (c = 1; c <= 2 * b - 1; c++) printf("%d", (((b - 1) % 10) + c -
1) % 10);
printf("\n");
}
return 0;
}
Third category
Special attention should be paid when the value entered is greater than 26 Hour , The return value required for output is A, And the output is of string type
int main()
{
int n;
int b, c, i, d;
scanf("%d", &n);
d = 'A';
for (b = 1; b <= n; b++)
{
for (i = 1; i <= n - b; i++)
{
printf(" ");
}
Output value , Because it is a string type , So %c, And d Is a representative string 'A', So we need to d Put it outside (( b - 1)%26)) Because when the n greater than 26 Hour , Output to be reset to A
for (c = 0; c < 2 * b - 1; c++)
{
printf("%c", d+(( b - 1)%26));
}
printf("\n");
}
return 0;
}
Fourth category
#include<stdio.h>
int main()
{
int n ;
int b, c, i, d, e;
scanf("%d", &n);
d = 'A';
for (b = 1; b <=n; b++)
{
for (i = 1; i <= n - b; i++)
{
printf(" ");
}
for (c = 0; c < b; c++)
{
printf("%c", d + c);
}
if (b > 1)
{
// When the number of rows is greater than one , character A plus e Value of
for (e = b - 2; e >= 0; e--)
printf("%c", d + e);
}
printf("\n");
}
return 0;
}
It's really not easy to write and summarize , I hope you will support me in the future , I hope to surprise you in the future creation !
Technology
Daily Recommendation