Set of instructions given to the compiler to execute set of statements. Until the condition becomes false, it is called Loop.
Assignment, While (condition) { Statement 1; Statement 2; Statement 3; …………………..
Increment | Decrement |
Assignment -> minCondition -> maxRelation -></<= Add(+) | Assignment -> maxCondition -> minRelation ->>/>= Sub(-) |
Print the no’s from 1 to 10:- From left to right Void main() { Int I; I=1; While(i<=100) { Printf(!”%d”,i); I=i+1; } } O/P : 12345678910 Print the no’s in decrement order from top Void main() { Int i; I=15; While(i>=10) { Printf(“\n%d”,i); I=i-1; } } o/p: 15 14 13 12 11 10
{ Int I,n; Clrscr(); Printf(“Enter a value: ”); Scanf(“%d”, &n); I=2; While(i<=n) { Printf(“%d”,i); I=i+2; } Getch(); } o/p:- Enter a value=10 2 4 5 6 10
Enter a value : 12345 Sum of 1+5=6
Case1: Enter two values: 10 20 10 12 14 16 18 20 Case 2: Enter two values: 9 20 10 12 14 16 18 20 Case 3: Enter two values 20 10 20 18 16 14 12 10 Case 4:- Enter two values: 21 10 20 18 16 14 12 10
{ Int n1,n2; Clrscr(); Printf(“Ener two values:”); Scanf(“%d %d”, &n1,&n2); If (n1<=n2) { If (n1%2!=0) || if(n1%2==1) N1=n1+1; While(n1<n2) { Printf(“%d”,n1); N1=n1+2; } Else { If(n1%2==1) || if (n1%2!=0) N1=n1-1; While(n1>=n2) { Printf(“%d”,n1); N1=n1-2; } } Getcch(); } Enter a value 50 0 1 2 3 5 8 13 21 34 Void main() { Int n,I,j,k; Clrscr(); Printf(“Enter a value”); Scanf(“%d”, &n); If(n>0) { I=0; J=1; Printf(“%d %d”,I,j); K=i+j; While(k<=n) { Printf(“%d”,k); I=j; J=k; K=i+j; } } Else Printf(“\ input should be >0”); Get ch(); }
Void main() { Int n,rn,sd,nd; Clrscr(); Printf(“Ener a value”); Scanf(“ %4d”,&n); Rn=sd=nd=0;
While (n>0){Rn=rn*10+n%10; Sd=sd+n%10; Nd=nd+1; N=n/10; } Printf(“\n Reverse value is:%d ”,m); Printf(“\n sum of digits : %d”,sd); Printf(“\n no.of digits :%d”,nd); Getch(); } o/p: Enter a value 1234 Reverse no: 4321 Sum of digits : 10 No.of digits : 4 |
N | Rn | Sd | Nd |
1234123 12 0 | 00+4=440+3 43 430+2 432 320+1 432 | 00+4=44+3 7 4+2 6 9+1 10 | 00+1=11+1 2 2+1 3 3+1 4 |
Void main() { Int n,I; Clrscr(); Printf(“enter a value”); Scanf(“%d”,&n); I=1; While(i<=10) { Printf(“\n %d * %2d=%2d”,n,I,n=i); I=i+1; } Getch(); o/p : 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45 5*10=50
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.