Answer:
The code is given in the explanation while the screenshots of the output are attached along. The basic steps of the pseudo code are as follows.
- Initialized the variables (counter and summation)
- Initialize the loop(for, while, do while)
- Estimate the remainder of value with 3 and if the value is 0, this indicates the value is a multiple of 3 so add it to the sum
- Re-iterate this until the value is greater than 1000.
- Print the results.
Step-by-step explanation:
The code is given as below
With For Loop
#include<stdio.h> //The library is added
int main(){ //the main function is initialized
int sum=0,i; //The variables are initialized
for(i=1;i<=1000;i++){ //The for loop is initiated with iterations from 1 to 1000
//with and increment of 1
if(i%3==0) //Remainder of i by 3 is calculated to identify multiples of 3
sum=sum+i; //summation is done
}
printf("Using for loop : ");//results are displayed
printf("Sum is %d.\\",sum);
With While Loop
i=1; //counter variable is initialized
sum=0; //summation variable is initialized
//infinite loop which breaks only when i becomes >1000
while(i){
if(i>1000) //condition which breaks only when i becomes >1000
break;
if(i%3==0)//Remainder of i by 3 is calculated to identify multiples of 3
sum=sum+i; //summation is done
i++;//counter is incremented
}
printf("Using while loop : ");//results are displayed
printf("Sum is %d.\\",sum);//results are displayed
With Do While Loop
i=1;//counter variable is initialized
sum=0;//summation variable is initialized
do{
if(i>1000) //condition which breaks only when i becomes >1000
break;
if(i%3==0)//Remainder of i by 3 is calculated to identify multiples of 3
sum=sum+i;//summation is done
i++;//counter is incremented
}while(i);
printf("Using do-while loop : ");//results are displayed
printf("Sum is %d.\\",sum);
return 0;
}