Difference between Do Loop and For Loop.
Do Loop :-
#include <stdio.h>
#include <stdlib.h>
int main()
{
float grade = 0;
float score = 0;
float tests = 0;
float average = 0;
printf("Press 0 when complete. \n\n" );
do{
printf("Test:%.0f Average:%.2f \n",tests,average);
printf("\n Enter test score : ");
scanf("%f",&score);
grade += score;
tests++;
average = grade / tests;
}while(score != 0);
return 0;
}
VS.
For Loop :-
#include <stdio.h>
#include <stdlib.h>
int main()
{
int noodles ;
for(noodles =1; noodles <=100; noodles+=8){
printf("Noodles is %d \n",noodles);
}
return 0;
}
Comments
Post a Comment