-->

Facebook

Jasper Roberts - Blog

Friday, April 10, 2015

Write a function program to add first N numbers.



#include <stdio.h>
#include <conio.h>

void main()
{
    int n;
clrscr();
numbers(n);
getch();
}

int numbers(int n)
{
int sum = 0, i;

   printf("Enter the number of integers you want to add\n");
   scanf("%d", &n);

   for (i = 1; i <= n; i++)
   {
      sum = sum + i;
   }

   printf("Sum of entered integers = %d\n",sum);

   return 0;
}

No comments:

Post a Comment