Google

Friday, January 15, 2010

CSC202 & ENG4033M : Loops


/*Counter Controlled Repetition */

#include "stdio.h"
int main()
{
int a = 10;
while(a > 0){
printf("%d\n",a);
a = a - 1;
}
return 0;
}

/*Sentinel Controlled Repetition */
#include "stdio.h"
int main()
{
int a = 0;

while(1){
printf("%d\n",a);
scanf("%d",&a);
if(a==-1) break;
}
return 0;
}





DO - WHILE Loops: