اكتب برنامج بلغة C لعرض مربع n من الأعداد الطبيعية ومجموعها

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

اكتب برنامج بلغة C لعرض مربع n من الأعداد الطبيعية ومجموعها

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

Input the number of terms : 5
                                                                                                              
The square natural upto 5 terms are :1  4  9  16  25
The Sum of Square Natural Number upto 5 terms = 55

الأجوبة

/*Write a program in C to display the n terms of square natural number and their sum*/

#include <stdio.h>

void main()
{
   int i,n,sum=0;
   printf("Input the number of terms : ");
   scanf("%d",&n);
   printf("\nThe square natural upto %d terms are :",n);
   for(i=1;i<=n;i++)
   {
     printf("%d  ",i*i);
     sum+=i*i;
   }
   printf("\nThe Sum of Square Natural Number upto %d terms = %d \n",n,sum);
}
هل كان المحتوى مفيد؟

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

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