Friday, 11 August 2017

Assignment 3: Group A


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;
}

21 comments:

  1. FE,Div:A,Batch:A3
    Roll no.:41

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. 3rd programme is the Best Programme And Easy To Run
    & Fine to Understand

    ReplyDelete
  4. impressive studying... nice use of projector...

    ReplyDelete
  5. Nice. Program A2 batch. Roll no 17

    ReplyDelete
  6. Good. Undestood
    Fe A2 batch roll no 17

    ReplyDelete
  7. Nice understood.
    A2 batch, roll no21

    ReplyDelete
  8. understood.
    A2 batch,Roll no 32

    ReplyDelete
  9. good understood Div-A Roll no.28 batch A2

    ReplyDelete
  10. Simple Forloop theory and program

    ReplyDelete