Write a Program Add n Numbers Without using an array.
#include <stdio.h>
int main()
{
int n;
int sum = 0;
int c, value;
printf ("Enter the number of integers you want to add\n");
scanf ("%d", &n);
printf ("Enter %d integers\n",n);
for (c = 1; c <= n; c++)
{
scanf ("%d",&value);
sum = sum + value;
}
printf ("Sum of entered integers = %d\n",sum);
return 0;
}
#include <stdio.h>
int main()
{
int n;
int sum = 0;
int c, value;
printf ("Enter the number of integers you want to add\n");
scanf ("%d", &n);
printf ("Enter %d integers\n",n);
for (c = 1; c <= n; c++)
{
scanf ("%d",&value);
sum = sum + value;
}
printf ("Sum of entered integers = %d\n",sum);
return 0;
}
No comments:
Post a Comment