图案打印一直是编程语言中一个有趣的话题。它强调在嵌套循环中使用内部循环和外部循环,并从中创建漂亮的图案。
下面提供了一些使用字母的模式。我们的任务是为以下给出的模式编写程序,以便当n =字母计数时,每个模式都应在给定输入’n’的基础上进行打印。
第一种模式:
C++
// C++ code for triangular
// patterns of alphabets
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = i; j <= n; j++)
{
cout << (char)('A' - 1 + j) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by
// shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
printf("%c", 'A' - 1 + j);
}
printf("\n");
}
return 0;
}
Java
class GFG
{
public static void main(String args[])
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
int ch = 65;
for (j = i; j <= n; j++)
{
System.out.print((char)(ch -1 + j) + " ");
}
System.out.print("\n");
}
}
}
// This code is contributed
// by Akanksha Rai
Python3
# Python 3 code for triangular
# patterns of alphabets
n = 5
for i in range(1, n + 1):
for j in range(i, n + 1):
print(chr(ord('A') - 1 + j), end = ' ')
print()
# This code is contributed
# by SamyuktaSHegde
C#
using System;
class GFG
{
public static void Main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
int ch = 65;
for (j = i; j <= n; j++)
{
Console.Write((char)(ch - 1 + j) + " ");
}
Console.Write("\n");
}
}
}
// This code is contributed
// by Akanksha Rai
PHP
Javascript
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = 1; j <= i; j++) {
cout << (char)('A' - 1 + i) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = 1; j <= i; j++) {
printf("%c ", 'A' - 1 + i);
}
printf("\n");
}
return 0;
}
Java
class GFG
{
// Driver code
public static void main(String[] args)
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
System.out.printf("%c ", 'A' - 1 + i);
}
System.out.printf("\n");
}
}
}
// This code is contributed by PrinciRaj1992
Python3
# Python3 code for triangular
# patterns of alphabets
n = 5
for i in range(n, 0, -1):
for j in range(1, i + 1, 1):
print(chr(ord('A') - 1 + i),
end = ' ')
print()
# This code is contributed by Rajput-Ji
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
// Driver code
public static void Main(String[] args)
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
Console.Write("{0} ",
(char)('A' - 1 + i));
}
Console.Write("\n");
}
}
}
// This code is contributed
// by Princi Singh
PHP
= 1; $i--)
{
for ($j = 1; $j <= $i; $j++)
{
echo chr(65 - 1 + $i)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
cout << (char)('A' + j - 1) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}
Java
import java.io.*;
class GFG
{
public static void main (String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
int ch = 65;
for (j = 1; j <= i; j++)
{
System.out.print(((char)ch));
ch++;
}
System.out.println();
}
}
}
//This code is contributed by m_kit
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
n = 5;
for i in range(1, n + 1):
for j in range(1, i + 1):
print(chr(ord('A') + j - 1),
end = " ");
print("");
# This code is contributed by 29AjayKumar
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
static public void Main ()
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
int ch = 65;
for (j = 1; j <= i; j++)
{
Console.Write(((char)ch));
ch++;
}
Console.WriteLine();
}
}
}
// This code is contributed by ajit
PHP
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = i; j <= n; j++) {
cout << (char)('A' + j - 1) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by Shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = i; j <= n; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}
Java
// Java code for triangular
// patterns of alphabets
class GFG
{
public static void main(String[] args)
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = i; j <= n; j++)
{
System.out.printf("%c ", ('A' + j - 1));
}
System.out.println("");
}
}
}
// This code is contributed by PrinciRaj1992
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
n = 5;
for i in range(n, 0, -1):
for j in range(i, n + 1, 1):
print(chr(ord('A') + j - 1),
end = " ");
print("");
# This code is contributed by Rajput-Ji
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
public static void Main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = i; j <= n; j++)
{
Console.Write("{0} ",(char)('A' + j - 1));
}
Console.WriteLine("");
}
}
}
// This code is contributed by Code_Mech
PHP
= 1; $i--)
{
for ($j = $i; $j <= $n; $j++)
{
echo chr(65 + $j - 1)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = n; j >= i; j--) {
cout <<(char)('A' - 1 + i)<<" ";
}
cout << endl;
}
return 0;
}
// This code is contributed by shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = n; j >= i; j--) {
printf("%c ", 'A' - 1 + i);
}
printf("\n");
}
return 0;
}
Java
/* Java program to find best
meeting point in 2D array*/
import java.util.*;
public class GFG
{
public static void main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = n; j >= i; j--)
{
System.out.printf("%c ", ('A' - 1 + i));
}
System.out.println("");;
}
}
}
// This code is contributed by 29AjayKumar
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
i, j, n = 0, 0, 5;
for i in range(1, n + 1):
for j in range(n, i - 1, -1):
print(chr(ord('A') - 1 + i), end = " ");
print("");
# This code is contributed by Princi Singh
C#
/* C# program to find best
meeting point in 2D array*/
using System;
class GFG
{
// Driver code
public static void Main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = n; j >= i; j--)
{
Console.Write("{0} ", (char)('A' - 1 + i));
}
Console.WriteLine("");;
}
}
}
// This code contributed by Rajput-Ji
PHP
= $i; $j--)
{
echo chr(65 - 1 + $i)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
C++
// C++ code for triangular
// patterns of alphabets
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = i; j >= 1; j--) {
cout << (char)('A' + j - 1) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by SHUBHAMSINGH10
C
// C code for triangular
// patterns of alphabets
#include
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = i; j >= 1; j--) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}
Java
// Java code for triangular
// patterns of alphabets
class GFG
{
public static void main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = i; j >= 1; j--)
{
System.out.printf("%c ", 'A' + j - 1);
}
System.out.printf("\n");
}
}
}
// This code is contributed by Rajput-Ji
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
i, j, n = 0, 0, 5;
for i in range(1, n + 1):
for j in range(i, 0, -1):
print(chr(ord('A') + j - 1),
end = " ");
print();
# This code is contributed by Rajput-Ji
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
// Driver code
public static void Main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = i; j >= 1; j--)
{
Console.Write("{0} ",
Convert.ToChar('A' + j - 1));
}
Console.Write("\n");
}
}
}
// This code is contributed by PrinciRaj1992
PHP
= 1; $j--)
{
echo chr(65 + $j - 1)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
输出:
A B C D E
B C D E
C D E
D E
E
第二种模式:
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = 1; j <= i; j++) {
cout << (char)('A' - 1 + i) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = 1; j <= i; j++) {
printf("%c ", 'A' - 1 + i);
}
printf("\n");
}
return 0;
}
Java
class GFG
{
// Driver code
public static void main(String[] args)
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
System.out.printf("%c ", 'A' - 1 + i);
}
System.out.printf("\n");
}
}
}
// This code is contributed by PrinciRaj1992
Python3
# Python3 code for triangular
# patterns of alphabets
n = 5
for i in range(n, 0, -1):
for j in range(1, i + 1, 1):
print(chr(ord('A') - 1 + i),
end = ' ')
print()
# This code is contributed by Rajput-Ji
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
// Driver code
public static void Main(String[] args)
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
Console.Write("{0} ",
(char)('A' - 1 + i));
}
Console.Write("\n");
}
}
}
// This code is contributed
// by Princi Singh
的PHP
= 1; $i--)
{
for ($j = 1; $j <= $i; $j++)
{
echo chr(65 - 1 + $i)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
输出:
E E E E E
D D D D
C C C
B B
A
第三模式:
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
cout << (char)('A' + j - 1) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}
Java
import java.io.*;
class GFG
{
public static void main (String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
int ch = 65;
for (j = 1; j <= i; j++)
{
System.out.print(((char)ch));
ch++;
}
System.out.println();
}
}
}
//This code is contributed by m_kit
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
n = 5;
for i in range(1, n + 1):
for j in range(1, i + 1):
print(chr(ord('A') + j - 1),
end = " ");
print("");
# This code is contributed by 29AjayKumar
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
static public void Main ()
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
int ch = 65;
for (j = 1; j <= i; j++)
{
Console.Write(((char)ch));
ch++;
}
Console.WriteLine();
}
}
}
// This code is contributed by ajit
的PHP
输出:
A
A B
A B C
A B C D
A B C D E
第四模式:
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = i; j <= n; j++) {
cout << (char)('A' + j - 1) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by Shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--) {
for (j = i; j <= n; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}
Java
// Java code for triangular
// patterns of alphabets
class GFG
{
public static void main(String[] args)
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = i; j <= n; j++)
{
System.out.printf("%c ", ('A' + j - 1));
}
System.out.println("");
}
}
}
// This code is contributed by PrinciRaj1992
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
n = 5;
for i in range(n, 0, -1):
for j in range(i, n + 1, 1):
print(chr(ord('A') + j - 1),
end = " ");
print("");
# This code is contributed by Rajput-Ji
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
public static void Main()
{
int i, j, n = 5;
for (i = n; i >= 1; i--)
{
for (j = i; j <= n; j++)
{
Console.Write("{0} ",(char)('A' + j - 1));
}
Console.WriteLine("");
}
}
}
// This code is contributed by Code_Mech
的PHP
= 1; $i--)
{
for ($j = $i; $j <= $n; $j++)
{
echo chr(65 + $j - 1)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
输出:
E
D E
C D E
B C D E
A B C D E
第五种模式:
C++
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = n; j >= i; j--) {
cout <<(char)('A' - 1 + i)<<" ";
}
cout << endl;
}
return 0;
}
// This code is contributed by shubhamsingh10
C
#include
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = n; j >= i; j--) {
printf("%c ", 'A' - 1 + i);
}
printf("\n");
}
return 0;
}
Java
/* Java program to find best
meeting point in 2D array*/
import java.util.*;
public class GFG
{
public static void main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = n; j >= i; j--)
{
System.out.printf("%c ", ('A' - 1 + i));
}
System.out.println("");;
}
}
}
// This code is contributed by 29AjayKumar
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
i, j, n = 0, 0, 5;
for i in range(1, n + 1):
for j in range(n, i - 1, -1):
print(chr(ord('A') - 1 + i), end = " ");
print("");
# This code is contributed by Princi Singh
C#
/* C# program to find best
meeting point in 2D array*/
using System;
class GFG
{
// Driver code
public static void Main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = n; j >= i; j--)
{
Console.Write("{0} ", (char)('A' - 1 + i));
}
Console.WriteLine("");;
}
}
}
// This code contributed by Rajput-Ji
的PHP
= $i; $j--)
{
echo chr(65 - 1 + $i)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
输出:
A A A A A
B B B B
C C C
D D
E
第六种模式:
C++
// C++ code for triangular
// patterns of alphabets
#include
using namespace std;
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = i; j >= 1; j--) {
cout << (char)('A' + j - 1) << " ";
}
cout << endl;
}
return 0;
}
// This code is contributed by SHUBHAMSINGH10
C
// C code for triangular
// patterns of alphabets
#include
int main()
{
int i, j, n = 5;
for (i = 1; i <= n; i++) {
for (j = i; j >= 1; j--) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}
Java
// Java code for triangular
// patterns of alphabets
class GFG
{
public static void main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = i; j >= 1; j--)
{
System.out.printf("%c ", 'A' + j - 1);
}
System.out.printf("\n");
}
}
}
// This code is contributed by Rajput-Ji
Python3
# Python3 code for triangular
# patterns of alphabets
if __name__ == '__main__':
i, j, n = 0, 0, 5;
for i in range(1, n + 1):
for j in range(i, 0, -1):
print(chr(ord('A') + j - 1),
end = " ");
print();
# This code is contributed by Rajput-Ji
C#
// C# code for triangular
// patterns of alphabets
using System;
class GFG
{
// Driver code
public static void Main(String[] args)
{
int i, j, n = 5;
for (i = 1; i <= n; i++)
{
for (j = i; j >= 1; j--)
{
Console.Write("{0} ",
Convert.ToChar('A' + j - 1));
}
Console.Write("\n");
}
}
}
// This code is contributed by PrinciRaj1992
的PHP
= 1; $j--)
{
echo chr(65 + $j - 1)." ";
}
echo "\n";
}
// This code is contributed by mits
?>
输出:
A
B A
C B A
D C B A
E D C B A
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。