Lab loop

465 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
465
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lab loop

  1. 1. LAB 5 Loop) C for Loop 2. while 3. do while
  2. 2. 1 1. 2. Dev-C 3. E-Draw 4. A4 1. (Flowchart) Dev-C 4.
  3. 3. for for
  4. 4. //1. for #include <stdio.h> #include <conio.h> int main() { int num; for (num=1;num<=10;num++) { printf("%dt",num); } getch(); return 0; } 1 2 3 4 5 6 7 8 9 10 //2. for #include <stdio.h> #include <conio.h> main() { printf("1t"); printf("2t"); printf("3t"); printf("4t"); printf("5t"); printf("6t"); printf("7t"); printf("8t"); printf("9t"); printf("10t"); getch(); }
  5. 5. for for 2 0 while #include <stdio.h> #include <conio.h> int main() { float num,sum; while (num!=0) { printf("Enter a number : "); scanf("%f",&num); sum=sum+num; printf("n"); }
  6. 6. printf("The summary = %10.2f : ",sum); getch(); return 0; } Enter a number : 10 Enter a number : 20 Enter a number : 30 Enter a number : 40 Enter a number : 50 Enter a number : 0 The summary = 150.00 while while a= a= answer = 'y'
  7. 7. while 3 factorial do - while #include <stdio.h> #include <conio.h> int main() { int a,fact,ans=1; printf("Please enter number : "); scanf("%d",&a); fact=a; do
  8. 8. { ans=ans*fact; printf("%dn",ans); fact- -; } while (fact>0); printf("n"); printf("The answer of %d! = %d",a,ans); getch(); return 0; } Please enter number :
  9. 9. The answer of ! = 120 do - while do -while
  10. 10. 10 for #include<stdio.h> #include<conio.h> main() { int i,in,sum; sum = 0; for (i=1;i<=10;i++) { printf("Enter weight : "); scanf("%d",&in); sum = sum+in; } printf("Summation of weights = %d",sum); getch();
  11. 11. }

×