Created
December 14, 2021 05:21
-
-
Save Shivani13121007/d48173b470273eb3156933b26ffe5508 to your computer and use it in GitHub Desktop.
pepcoding_pattern1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
cin>>n; | |
if(n<=0 || n>26) | |
{ | |
cout<<"Enter a Valid number"; | |
return 0; | |
} | |
for(int i =1;i<=n;i++) | |
{ | |
for(int j=1;j<=i;j++) | |
{ | |
if(i%2 == 0) cout<<(char)(j+64)<<" "; | |
else cout<<j<<" "; | |
} | |
cout<<endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String args[]) { | |
Scanner scn = new Scanner(System.in); | |
int n = scn.nextInt(); | |
if(n<=0 || n>26) | |
{ | |
System.out.println("Enter a Valid number"); | |
return; | |
} | |
for(int i=1;i<=n;i++) | |
{ | |
for(int j =1;j<=i;j++) | |
{ | |
if(i%2 == 0) System.out.print((char)(j+64) + " "); | |
else System.out.print(j + " "); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment