C Program which takes input upto given times and add it all:
#include <stdio.h>
main()
{
int n, sum = 0, c, value;
printf("Enter the number of integers you want to add: ");
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",sum);
}
Also by Making Function of it:
#include <stdio.h>
void addnumbers(int);
main()
{
int n;
printf("Enter the number of integers you want to add: ");
scanf("%d",&n);
addnumbers(n);
}
void addnumbers(int n)
{
int sum = 0, c, value;
printf("Enter %d integers\n",n);
for (c = 1; c <= n; c++)
{
scanf("%d",&value);
sum = sum + value;
}
printf("Sum of entered integers = %d",sum);
}
{[['
']]}

0 comments:
Post a Comment