+ 1
If i want to add first positive 15 numbers what should i code using while loop ()
Using while loop If some one can then help me thanks
4 Answers
+ 3
Yes , you can use while/for loop for that ....
+ 3
Declare one variable for storing sum and one variable for control while loop and that same variable can be used to calculate sum of first 15 numbers.
C program for adding first 15 positive number is like this
#include<stdio.h>
int main()
{
int sum=0; //for storing addition
int i=1; //for control while loop
while(i<16)
{
sum=sum+i;
i++;
}
printf ("%d",sum)
return 0;
}
+ 3
For loop a bit more straightforward for this but while loop can do it.
+ 2
int i=0
int sum=1
while(i<=15) {
sum=sum+i;
i++;
}