0% found this document useful (0 votes)
17 views

C Programming Pattern Solution

Uploaded by

gy384672
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

C Programming Pattern Solution

Uploaded by

gy384672
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

C-Programming Pattern

A.
123454321
1234321
12321
121
1

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, k;
printf(" ");
for (i=5; i>=1; i--)
{
for (j=5-i; j>=1; j--)
printf(" ");
for (j=1,k=2*i-1; j<=2*i-1; j++,k--)
{
if (j <= k)
printf("%d",j);
else
printf("%d",k);
}
printf("\n");

printf(" ");

return 0;
}

Er. Sandesh S Poudel


C-Programming Pattern

B.
N
NE
NEP
NEPA
NEPAL
#include<stdio.h>
int main()
{
char str[20];
int i,j;
printf("Enter a string: ");
scanf("%s",str);
for(i=0; str[i]!='\0'; i++)
{
for(j=0; j<=i; j++)
{
printf("%c", str[j]);
}

printf("\n");
}

return 0;
}

Er. Sandesh S Poudel


C-Programming Pattern

C.

N
Ne
Nep
Nepa
Nepal
Nepa
Nep
Ne
N

#include<stdio.h>
#include<stdlib.h>
int main()
{
char str[20];
int len,i,j, place;
printf("Enter a string: ");
scanf("%s", str);
for(len=0; str[len]!='\0'; len++);
len--;
for(i=0; i<(2*len+1); i++)
{
if(i<len) place = i;
else place = abs(2*len - i);
for(j=0; j<=place; j++)
printf("%c",str[j]);
printf("\n");
}

return 0;
}

Er. Sandesh S Poudel


C-Programming Pattern

D.

N
eee
PPPPP
aaaaaaa
LLLLLLLLL
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, k;
char s[]={"NePaL"};
printf(" ");
for (i=0; i<5; i++)
{
for (j=5-i; j>=1; j--)
printf(" ");
for (j=1;j<=2*i+1;j++)
{
printf("%c",s[i]);
}
printf("\n");
printf(" ");
}
return 0;
}

Er. Sandesh S Poudel


C-Programming Pattern

E.

Programming
rogrammin
ogrammi
gramm
ram
a

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j;
char s[]={"Programming"};
for (i=0; i<11; i++)
{
for (j=i;j<11-i;j++)
{
printf("%c",s[j]);
}
printf("\n");
}
return 0;
}

Er. Sandesh S Poudel


C-Programming Pattern

F.
P
PU
PuL
PULC
PuLcH
PULCHO
PuLcHoW
PULCHOWK
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
int i, j;
char s[]={"pulchowk"};
for (i=0; i<8; i++)
{
for (j=0;j<=i;j++)
{
if(j%2!=0||i==j)
{
if(s[j]>='a'&& s[j]<='z')
{
s[j]=s[j]-32;
printf("%c",s[j]);
}
else
{
s[j]=s[j]+32;
printf("%c",s[j]);
}
}
else
printf("%c",s[j]);
}
printf("\n");
}
return 0;
}

Er. Sandesh S Poudel

You might also like