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

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

View Full Document Right Arrow Icon
//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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online