اكتب برنامج بلغة C لعرض نمط لعدد n من الصفوف باستخدام رقم سيبدأ بالرقم 1 وسيكون الرقم الأول والأخير من كل صف هو 1

  • برمجة
  • برمجة سي c

اكتب برنامج بلغة C لعرض هذا النمط لعدد n من الصفوف باستخدام رقم سيبدأ بالرقم 1 وسيكون الرقم الأول والأخير من كل صف هو 1

الخرج المتوقع :

Input number of rows : 5
                                                                                                              
    1
   121
  12321
 1234321
123454321

الأجوبة

/*Write a program in C to display the such a pattern for n number of rows using a number which will start with the number 1 and the first and a last number of each row will be 1*/

#include <stdio.h>

void main()
{
   int i,j,n;
   printf("Input number of rows : ");
   scanf("%d",&n);
   for(i=0;i<=n;i++)
   {
     /* print blank spaces */
     for(j=1;j<=n-i;j++)
	printf(" ");
     /* Display number in ascending order upto middle*/
     for(j=1;j<=i;j++)
       printf("%d",j);
 
     /* Display  number in reverse order after middle */
       for(j=i-1;j>=1;j--)
	  printf("%d",j);
 
     printf("\n");
   }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...