اكتب برنامج بلغة C لعرض عدد n من الأعداد الطبيعية الفردية ومجموعها
- برمجة
- برمجة سي c
- 2021-05-04
- Wassim
الأجوبة
/*Write a program in C to display the n terms of odd natural number and their sum*/
#include <stdio.h>
void main()
{
int i,n,sum=0;
printf("Input number of terms : ");
scanf("%d",&n);
printf("\nThe odd numbers are :");
for(i=1;i<=n;i++)
{
printf("%d ",2*i-1);
sum+=2*i-1;
}
printf("\nThe Sum of odd Natural Number upto %d terms : %d \n",n,sum);
}