Write a program to print below pattern.
input: 2 4 5 6 7 8
pattern :
245678
45678
5678
678
78
8Explanation
1.सबसे पहले यूजर से pattern के लिए digits को input करा लेते है | जिसे array मे insert करा लेते है |
2.उसके बाद count () function से array की length को calculate करते है जिसे length variable मे assign करते है |
3.Loop चलाया जाता है जिसमे i को 1 से initial किया जाता है|
#include<conio.h>
void main()
{
int i,j ;
printf(“Enter digits”);
for()
for(i=0;i<20;i++)
{
scanf(“%d”,&a[i]);
}
int length = count(a);
for(i=0;i<length;i++)
{
for(j=i;j<length;j++)
{
printf(“%d”,a[j]);
}
printf(“\n”);
}
}int count(int c[ ])
{
int k;
int count =0;
for(k=0;k<20;k++)
{
if(c[k]==’ ‘)
{
return (count);
}
else
{
count++;
}
}
return (count) ;
}
आउटपुट होगा :
Enter digits 2 4 5 6 7 8
245678
45678
5678
678
78
8
उदहारण -2 :
Write a program to print below pattern.
Enter Number : 23456
23456
3456
456
56
6
Explanation
1. सबसे पहले , number को input करते है जिसे number variable मे assign कर देते है |
2. for loop चलाया जाता है :-
number की last डिजिट को eliminate कर देते है |
3. loop तब तक चलाया जाता है जबतक की number की value ‘0’ नहीं हो जाती है |
#include<conio.h>
void main()
{
int number ;
printf(“Enter Number”);
scanf(“%d”,&number );
for( n=number ; n!=0 ; number = number /10 )
{
printf(“%d\n”,n);
getch()
}आउटपुट होगा :
Enter Number 123345
123345
12334
1233
123
12
1
उदहारण -3 :
Write a program to print below pattern.
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
Explanation
1.सबसे पहले यूजर से row और column की number को input करा लेते है |
2.फिर उसके बाद दो variable i और j को declare कर लेते है |
3.Loop 1 चलाया जाता है जिसमे i को 1 से initial किया जाता है|
if((i%2)==0)
{
k=k++;
}
else
{
k-=k–;
}
Write a program to print below pattern.
1
22
333
4444
33333
222222
11111111
#include<conio.h>
void main()
{
int i,j ;
printf(“Enter Row Number”);
scnaf(“%d”,&r);
printf(“Enter Column Number “);
scnaf(“%d”,&c);
for(i=1;i<=r;i++)
{
{
for(j=1;j<=i,j++)
{
printf(“%d”, i+1);
}
}
else
{
for(j=0;j<=i;j++)
{
printf(“%d , r-i+1);
}
}
}
getch();
}
आउटपुट होगा :
Enter Row Number 7
Enter Column Number 7
1
22
333
4444
33333
222222
11111111
Write a program to print below pattern.
1
2 7
3 8 12
4 9 13 16
5 10 14 17 19
6 11 15 18 20 21
inner loop मे , k की value print होती है |और ककी value मे value + num से increment होगा |
और num मे ‘1’ से decrement हो जायेगा |
#include<conio.h>
void main()
{
int i,j,k,num;
printf(“Enter Row Number”);
scnaf(“%d”,&r);
printf(“Enter Column Number “);
scnaf(“%d”,&c);
for(i=1;i<=r;i++)
{
k=i;
for(j=1;j<=i;j++)
{
printf(“%d”,k);
k=k+num;
num–;
}
}
getch();
}
आउटपुट होगा :
Enter Row Number 6
Enter Column Number 6
1
2 7
3 8 12
4 9 13 16
5 10 14 17 19
6 11 15 18 20 21
Write a program to print below pattern.
2
242
24642
2468642Explanation
1.सबसे पहले यूजर से row की number को input करा लेते है |
2.फिर उसके बाद दो variable i और j को declare कर लेते है |
3.दो inner loop चलाया जाता है |
पहले inner loop मे , j की value ‘2’ से initial करते है | और ‘2’ से increment करते है क्योकि सम number print करना है |इस ‘j’ की value को print करा लेते है |ये loop tan तक चलता है जब की j की value i*2 नहीं हो जाती है |इस inner loop से निन्म पैटर्न print होता है |
2
24
246
2468
दुसरे inner loop मे , j को (i-1)*2 से initial करते है |और ‘2’ से decrements होता है |ये loop तब तक चालत है जब तक j की value ‘2’ नहीं हो जाती है |इअमे भी ‘j’ की value print होती है |
#include<conio.h>
void main()
{
int i,j,k,num;
printf(“Enter Row Number”);
scnaf(“%d”,&r);
for(i=1;i<=r;i++)
{
{
printf(“%d”,j);
}
for(j=(i-1)*2;j>=2;j=j-2)
{
printf(“%d”,j);
}}
}
getch();
}
आउटपुट होगा :
Enter Row Number 4
2
242
24642
2468642