Professional Documents
Culture Documents
LAB # 13 To Understand The Control Structure Using WHILE and DO While Loop
LAB # 13 To Understand The Control Structure Using WHILE and DO While Loop
int main () {
return 0;
}
Program 2
1. #include<stdio.h>
2. int main(){
3. int i=1,number=0,b=9;
4. printf("Enter a number: ");
5. scanf("%d",&number);
6. while(i<=10){
1
7. printf("%d \n",(number*i));
8. i++;
9. }
return 0;
}
SYNTAX:
do
{
statement; / Block
}
while (condition_expr);
Also note that the Do-While ends with a semicolon.
Program 3
This program will execute once, even if the initial value of feet is 0
// Program to add numbers until the user enters zero
#include <stdio.h>
int main() {
double number, sum = 0;
printf("Sum = %.2lf",sum);
return 0;
}
2
3
Program 4
#include <stdio.h>
int main ()
{
char size;
printf("Enter the letter on the tag of your shirt [X, L, M, S]:");
scanf("%c",&size);
switch (size)
{
case 'X':
printf("Your shirt's size is Extra Large\n");
break;
case 'L':
printf("Your shirt's size is Large\n");
break;
case 'M':
printf( "Your shirt's size is Medium\n");
break;
case 'S':
printf( "Your shirt's size is Small\n");
break;
default:
printf( "The entered letter is invalid\n");
}
return 0;
}
4
LAB TASK:
Lab Task. 14.1) Write a program to generate a number table of the given value. The user
should be asked for RE-RUN or EXIT the program giving up the following massage; “Do
You Want To Continue (Y/N)”.
Lab Task. 14.2) Write a program to find a factorial using while loop.