{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

For Loops

# For Loops - /for looops/entrance controlled condition to do...

This preview shows pages 1–2. Sign up to view the full content.

//for looops //entrance controlled: condition to do loop is at top, min #exec=0 //can be deterministic: # of times to do loop is known //can be indeterministic: # of times to do loop is not known //create table conv from celcius to fahrenheit #include <stdio.h> void main() { float f,c,s,e,i; printf("Enter start,end,increment "); scanf("%f%f%f",&s,&e,&i); for(c=s;c<=e;c+=i) { f=(9.0/5.0)*c+32.0; printf("%f %f\n",c,f); } } /* Enter start,end,increment -50 100 25.6 -50.000000 -58.000000 -24.400000 -11.919999 1.200001 34.160000 26.800001 80.240005 52.400002 126.320000 78.000000 172.399994 Press any key to continue . . . */ /* sum+avg of 5 numbers using for loop #include <stdio.h> void main() { int num,sum=0; float avg; for(int i=1;i<=5;i++) { printf("Enter a number "); scanf("%d",&num); sum+=num; } avg=sum/(float)100; printf("%d %f\n",sum,avg); } */ /* Enter a number 5 Enter a number 694 Enter a number 415 Enter a number 4856 Enter a number 4614 10584 105.839996 Press any key to continue . . . */ /* Find largest of 5 numbers using for loop #include <stdio.h> void main() { int num,big; printf("Enter a number "); scanf("%d",&big);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
for(int i=2;i<=5;i++) { printf("Enter a number "); scanf("%d",&num);
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

For Loops - /for looops/entrance controlled condition to do...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online