You are on page 1of 6

Iterative or Repetitive Control Statements

S y n ta xa nd Flow C ha rt for D oWhile S ta tem ent


S y n t a x : d o { s ta tem en ts; (increm en t/decrem ent); } w h ile (condition);

S y nta xa nd Flow C ha rt for While S ta tem ent


S y n t a x : while(condition) { s ta tem en ts; in crem en t/decrem en t; }

S y nta xa nd Flow C ha rt for FO S ta tem ent


S y n t a x : f o r (initia lisa tion; tes tcondition; incre/decre) { s ta tem ents; }

/*WAP to print Hello 10 times by using While loop*/ #include<stdio.h> main ! " int i#1$ %hile i<#10! " print& 'Hello(n'!$ i))$ * *

/*WAP to &ind the +actorial o& a gi,en number by using While loop*/ #include<stdio.h> main ! " int n-i#1-&act#1$ print& '.nter any integer/ '!$ scan& '0d'-1n!$ %hile i<#n! " &act#&act*i$ i))$ * print& '2he &actorial o& 0d is/ 0d(n'-n-&act!$ * /*WAP to print Hello 10 times using 4o5While loop*/ #include<stdio.h> main ! " int i#1$ do " print& 'Hello(n'!$ i))$ *%hile i<#10!$ *

/*WAP to print the multiplication table o& gi,en number using %hile loop*/ #include<stdio.h> main ! " int n-i#1$ print& '.nter any integer/ '!$ scan& '0d'-1n!$ %hile i<#30! " print& '03d * 03d # 03d(n'-n-i-n*i!$ i))$ * * /*WAP to &ind the &actorial o& a gi,en number using 4o5While loop*/ #include<stdio.h> main ! " int i#1- &act#1- n$ print& '.nter a 6umber/ '!$ scan& '0d'-1n!$ do " &act#&act*i$ i))$ *%hile i<#n!$ print& '2he &actorrial o& 0d is 0d'-n-&act!$

/*WAP to print the multiplication table o& a gi,en number using 4o5While loop*/ #include<stdio.h> main ! " int i#1- n$ print& '.nter a 6umber/ '!$ scan& '0d'-1n!$ do " print& '03d *03d #03d(n'-n-i-n*i!$ i))$ *%hile i<#10!$ *

/*WAP to &ind the gi,en number is e,en or not*/ #include<stdio.h> ,oid main ! " int i#1-n$ clrscr !$ print& '.nter a number/ '!$ scan& '0d'-1n!$ %hile i<#n! " i& i07##0! print& '0d(n'-i!$ i))$ * getch !$

/*WAP to print the is e,en numbers bet%een gi,en range*/ #include<stdio.h> main ! " int i- &irst- last- n$ print& '.nter &irst and last numbers/ '!$ scan& '0d0d'-1&irst-1last!$ &or n#&irst$n<#last$n))! " i#n$ %hile i<#n! " i& i07##0! print& '0d(n'-i!$

* * /*WAP to &ind the gi,en number is 8dd or not*/ #include<stdio.h> ,oid main ! " int i#1-n$ clrscr !$ print& '.nter a number/ '!$ scan& '0d'-1n!$ %hile i<#n! " i& i079#0! print& '0d(n'-i!$ i))$ * getch !$ * *

i))$

/*WAP to print the is 8dd numbers bet%een gi,en range*/ #include<stdio.h> main ! " int i-&irst- last- n$ print& '.nter &irst and last numbers/ '!$ scan& '0d0d'-1&irst-1last!$ &or n#&irst$n<#last$n))! " i#n$ %hile i<#n! " i& i079#0! print& '0d(n'-i!$ i))$ * * *

/*WAP to &ind the A,erage o& 6 */ #include<stdio.h> ,oid main ! " int i#1- n-sum#0-m$ &loat a,g$ clrscr !$ print& '.nter a number/ '!$ scan& '0d'-1n!$ m#n$ %hile i<#n! " sum#sum)n$ n55$ * print& 'sum# 0d(n'-sum!$ a,g# &loat!sum/m$ print& 'A,erage# 0&'-a,g!$ getch !$ * /*WAP to &ind the ;e,erse o& a gi,en number using While*/ #include<stdio.h> main ! " int n-a-b-sum$ print& '.nter a 6umber/ '!$ scan& '0d'-1n!$ sum#0$ %hile n>0! " a#n010$ sum#sum*10)a$ n#n/10$ * print& '2he re,erse o& gi,en number is 0d(n'-sum!$

/*WAP to &ind the :umo&4i,isors o& 6*/ #include<stdio.h> main ! " int n-i#1-sum#0$ print& '.nter a number/ '!$ scan& '0d'- 1n!$ %hile i<#n! " i& n0i##0! " print& '0d(n'-i!$ sum#sum)i$ * i))$ * print& 'sum ,alue #0d'-sum!$

/*WAP to &ind the ;e,erse o& a gi,en number using 405While*/ #include<stdio.h> main ! " int n-a-b-sum$ print& '.nter a 6umber/ '!$ scan& '0d'-1n!$ sum#0$ do " a#n010$ sum#sum*10)a$ n#n/10$ *%hile n>0!$ print& '2he re,erse o& gi,en number is 0d(n'-sum!$

/*WAP to &ind the gi,en number is Palindrome or not*/ #include<stdio.h>

/*WAP to print palindrome numbers bet%een range*/ #include<stdio.h>

main ! " int n-m-a-b-sum$ print& '.nter a 6umber/ '!$ scan& '0d'-1n!$ m#n$ sum#0$ %hile n>0! " a#n010$ sum#sum*10)a$ n#n/10$ * print& '2he re,erse o& gi,en number is 0d(n'-sum!$ i& sum##m! print& '0d is Palindrome'-m!$ else print& '0d is not Palindrome'-m!$ *

,oid main ! " int i-<-n-a-re,#0-m-&irst-last$ clrscr !$ print& '.nter a &irst and last numbers/ '!$ scan& '0d0d'-1&irst-1last!$ &or i#&irst$i<#last$i))! " n#i$ re,#0$ %hile n>0! " a#n010$ re,#re,*10)a$ n#n/10$ * i& re,##i! print& '0d '-i!$ * getch !$ * /*WAP to print the is Per&ect numbers bet%een gi,en range*/ #include<stdio.h> main ! " int n-i-sum#0-&irst-last$ print& '.nter &irst and last numbers/ '!$ scan& '0d0d'- 1&irst-1last!$ &or n#&irst$n<#last$n))! " sum#0$ &or i#1$i<n$i))! " i& n0i##0! sum#sum)i$ * i& sum##n! print& '0d '-n!$ * *

/*WAP to &ind the gi,en number is Per&ect or 4e&icient or Abundant*/ #include<stdio.h> main ! " int n-i-sum#0$ print& '.nter a number/ '!$ scan& '0d'- 1n!$ &or i#1$i<#n/7$i))! " i& n0i##0! sum#sum)i$ * i& sum##n! print& '0d is per&ect number'-n!$ else i& sum<n! print& '0d is de&icient number'-n!$ else print& '0d is abundant number'-n!$ * /*WAP to print the is 4e&icient numbers bet%een gi,en range*/ #include<stdio.h> main ! " int n-i-sum#0-&irst-last$ print& '.nter &irst and last numbers/ '!$ scan& '0d0d'- 1&irst-1last!$ &or n#&irst$n<#last$n))! " sum#0$ &or i#1$i<n$i))! " i& n0i##0! sum#sum)i$ * i& sum<n! print& '0d '-n!$ * * /*WAP to chec= the gi,en number is Armstrong or not*/ #include<stdio.h>

/*WAP to print the is Abundant numbers bet%een gi,en range*/ #include<stdio.h> main ! " int n-i-sum#0-&irst-last$ print& '.nter &irst and last numbers/ '!$ scan& '0d0d'- 1&irst-1last!$ &or n#&irst$n<#last$n))! " sum#0$ &or i#1$i<n$i))! " i& n0i##0! sum#sum)i$ * i& sum>n! print& '0d '-n!$ * *

/*WAP to print the Armstrong numbers bet%een gi,en range*/ #include<stdio.h>

main ! " int n-m-a-b-sum$ print& '.nter a 6umber/ '!$ scan& '0d'-1n!$ m#n$ sum#0$ %hile n>0! " a#n010$ b#a*a*a$ sum#sum)b$ n#n/10$ * i& sum##m! print& '0d is Armstrong'-m!$ else print& '0d is not an Armstrong'-m!$ *

main ! " int i-n-m-a-b-sum-&irst-last$ print& '.nter &irst and last numbers/ '!$ scan& '0d0d'-1&irst-1last!$ &or i#&irst$i<#last$i))! " n#i$ sum#0$ %hile n>0! " a#n010$ b#a*a*a$ sum#sum)b$ n#n/10$ * i& sum##i! print& '0d(n'-i!$ * *

/*WAP to chec= the gi,en number is :trong or not*/ #include<stdio.h> main ! " int i-m-n-a-&act-sum$ print& '.nter a number/ '!$ scan& '0d'-1n!$ &or sum#0-m#n$m>0$m#m/10! " a#m010$ &or &act#1$a>0$a55! &act#&act*a$ sum#sum)&act$ * i& sum##n! print& '0d is strong'-n!$ else print& '0d is not strong'-n!$ *

/*WAP to print the is :trong numbers bet%een gi,en range*/ #include<stdio.h> main ! " int i-m-n-a-&act-sum-&irst-last$ print& '.nter &isrt and last numbers/ '!$ scan& '0d0d'-1&irst-1last!$ &or n#&irst$n<#last$n))! " &or sum#0-m#n$m>0$m#m/10! " a#m010$ &or &act#1$a>0$a55! &act#&act*a$ sum#sum)&act$ * i& sum##n! print& '0d '-n!$ * * /*WAP to print Prime numbers bet%een range*/ #include<stdio.h> main ! " int n- i#1- count- &irst- last$ print& '.nter a &irst and last numbers/ '!$ scan& '0d0d'-1&irst-1last!$ &or n#&irst$n<#last$n))! " count#0$ &or i#1$i<#n$i))! i& n0i##0! count))$ i& count##7! print& '0d '-n!$ * *

/*WAP to &ind the gi,en number is Prime or not*/ #include<stdio.h> main ! " int n-i#7-c#0$ print& '.nter n ,alue/ '!$ scan& '0d'-1n!$ %hile i<n! " i& n0i##0! c))$ i))$ * i& c##011n9#1! print& '0d is prime'-n!$ else print& '0d is not prime'-n!$ * /*WAP to print the +ibonacci series o& a gi,en number*/ #include<stdio.h> ,oid main ! " int a#0-b#1-c-n$

/*WAP to print +ibonacci numbers up to gi,en numbers*/ #include<stdio.h> main ! " int a#0-b#1-c-n-&irst-last$

clrscr !$ print& '.nter a number/ '!$ scan& '0d'-1n!$ print& '0d 0d '-a-b!$ c#a)b$ %hile c<#n! " print& '0d '-c!$ a#b$ b#c$ c#a)b$ * getch !$

print& '.nter &irst and last numbers/ '!$ scan& '0d 0d'-1&irst-1last!$ c # a)b$ i& &irst > last! " print& '>n,alid series options'!$ e?it 0!$ * i& &irst ## 0 11 last ##0! print& '0 '!$ i& &irst ##0 11 last 9#0! print& '0 1 '!$ i& &irst ## 1! print& '1 '!$ %hile c<#last! " i& c>#&irst! print& '0d '-c!$ a # b$ b # c$ c # a)b$ * *

/*WAP to @A4 o& a gi,en number*/ #include<stdio.h> ,oid main ! " int m-n-a-b-r$ clrscr !$ print& '.nter t%o nos/ '!$ scan& '0d 0d'-1m-1n!$ i& m>n! " a#m$ b#n$ * else " a#n$ b#m$ * r#a0b$ %hile r9#0! " a#b$ b#r$ r#a0b$ * print& '@A4 # 0d'-b!$ getch !$ *

/* Write a A program to accept a decimal number and con,ert it to binary and count the number o& 1Bs in the binary number*/ #include <stdio.h> main ! " long int n- m- bin # 0- base # 1$ int rem- ones # 0 $ print& '.nter a decimal integer '!$ scan& '0d'- 1n!$ /*ma?imum &i,e digits */ m # n$ %hile n > 0! " rem # n 0 7$ i& rem##1! /*2o count no.o& 1s*/ " ones))$ * bin # bin ) rem * base$ n#n/7$ base # base * 10$ * print& '>nput number is # 0ld(n'- m!$ print& '>ts Cinary eDui,alent is # 0ld(n'- bin!$ print& '6o.o& 1Bs in the binary number is # 0d(n'- ones!$ *

You might also like