Aim:"Program in C to calculate the sum of all numbers from 0 to 100 (both inclusive) that are divisible by 4."
Theory :
For Loop:
- The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.
- Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop.
- After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition.
- The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the 'for' loop terminates.
//Program:
#include<stdio.h>
int main()
{
int i, sum=0 ;
for(i=0;i<=100;i++)
{
if(i%4==0)
{
printf("\t %d",i);
sum=sum+i;
}
}
printf("\n Sum = %d\n",sum);
return 0;
}
FE,Div:A,Batch:A3
ReplyDeleteRoll no.:41
This comment has been removed by the author.
ReplyDeleteNyc teaching roll no 30
ReplyDelete3rd programme is the Best Programme And Easy To Run
ReplyDelete& Fine to Understand
FE chem Div : A
ReplyDeleteRoll No: 33
impressive studying... nice use of projector...
ReplyDeleteNice. Program A2 batch. Roll no 17
ReplyDeleteGood. Undestood
ReplyDeleteFe A2 batch roll no 17
Nice understood.
ReplyDeleteA2 batch, roll no21
understood.
ReplyDeleteA2 batch,Roll no 32
Easy to learn...
ReplyDeleteunderstood
ReplyDeleteFE(A)
Roll no - 35
Nice , understood
ReplyDeletegood understood Div-A Roll no.28 batch A2
ReplyDeleteSimple Forloop theory and program
ReplyDeleteWell understood
ReplyDeleteEasy to learn
ReplyDeleteunderstood
ReplyDeleteunderstood
ReplyDeleteUnderstood
ReplyDeleteGood understood
ReplyDelete