/*
Use the for loop structure to calculate the sum algorithm of integers within 1-100
: 1. Define the variable i, traverse the integers; define the variable sum to calculate the sum
2, for loop structure
3, output the result
*/
#include<stdio.h>
int main()
{
int i,sum=0;
int count=0;//Define variable count to record the number of loops
for(i=1;i<=100;i++)
{
sum = sum +i;
count = count+1;//The value of count is incremented by 1 after each loop;
}
printf("The sum is:%d\n",sum);
printf("The number of loops is:%d\n",count);
return 0;
}
Use the for loop structure to calculate the sum algorithm of integers within 1-100
: 1. Define the variable i, traverse the integers; define the variable sum to calculate the sum
2, for loop structure
3, output the result
*/
#include<stdio.h>
int main()
{
int i,sum=0;
int count=0;//Define variable count to record the number of loops
for(i=1;i<=100;i++)
{
sum = sum +i;
count = count+1;//The value of count is incremented by 1 after each loop;
}
printf("The sum is:%d\n",sum);
printf("The number of loops is:%d\n",count);
return 0;
}