I am new to coding
I am trying to print a pattern,
ABCDEF
G$$$$H
I$$$$J
K$$$$L
M$$$$N
OPQRST
for input N=6
my cpp code for the same is
#include <iostream>
using namespace std;
//This function takes the input size for the pattern
void printPattern(int N)
{
int i;//variable for outer loop
int j;//variable for inner loop
int c=65;
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
{
if(i==1||i==N||j==1||j==N)
{
char ch;
ch=c;
cout<<ch;
c++;
}
else
{
cout<<"$";
}
}
cout<<"\n";
}
}
int main() {
int T,N;
cin>>T;
for(int i=1;i<=T;i++)u
{
cin>>N;
printPattern(N);
return 0;
}
}
It is running perfectly fine for any all the inputs i provide manually but on submitting the code it gives unexpected failing of test cases,e.g. for N=5. I tried giving N as 5 and the output is perfectly fine. can anyone point out where's the problem?
Aucun commentaire:
Enregistrer un commentaire