0% found this document useful (0 votes)
2 views

chapter 3

The document contains various programming exercises and solutions focused on concepts such as palindromes, Armstrong numbers, greatest common divisors, least common multiples, and generating patterns. Each program is written in C and includes instructions for implementation, along with example outputs. The content serves as a practical guide for learning computer programming techniques.

Uploaded by

mangeshdhamke823
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2 views

chapter 3

The document contains various programming exercises and solutions focused on concepts such as palindromes, Armstrong numbers, greatest common divisors, least common multiples, and generating patterns. Each program is written in C and includes instructions for implementation, along with example outputs. The content serves as a practical guide for learning computer programming techniques.

Uploaded by

mangeshdhamke823
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
WE es i Con ' %< Computer Programming (Dr. BATU) 3.25 SS Foy rogram 3, ee ee Write a Palindrome na thal chocks whether the given number is @ its reverse. OF Net: Palindrome is a number which is equal to "Se. For ex. §, 121, 7667, 24842.0tc, Soln, : # include void — main() int n,d,rev,orig; scanf("%d*,&n); origen; Tev=0; while(n>0) { den%10; n=n/10; reverev*10+d; + if(orig—rev) printf("The given number is a palindrome\n"); else printf("The given number is not palindrome\n"); } Program 3.6.59 Write a program that reads a number and display whether it is an Armstrong number or not. Armstrong number is a umber which is equal to the sum of the cube of i's digit. Ex. 153, 370, 371 ete, (153 = 19 + 59 +39) soln. # include void — main() t int n,d,sum,x; scanf(*%bd",&n); xen; sum=0; while(x>0) { d=x%10; x=x/10; sum = sum + d*d*d; } if(neesum) printf(*Tt is an Armstrong number\9"), else printf("t is not Armstrong number\n*), L} ______————__] roan 9860 Pr ty tats a AMONG rumbusb 101000. Soin. # include void main() f int n,x,sum,ds for(ne1;n<=1000;n+) { xl sams 0 xen; sum=0; while(x>0) { dexyao, d= W120 = © rexfio; BE Wve = sumesum+d*d*d; Suez } if{sum==n) printf("bd\n",n); x0 (0) } Program 2.6.61 Write a program that finds the greatest common divisor (GC) of given two numbers. Soln.: # include void main() { scanf("%ed%d" 8a, 8b); while(a!eb) if(arb) ana-b; else b=b-a; } brintf("The GCD=%d\n",a); “Scanned with CamScanner = Wirito @ program 10 road two numbors and find tholr {Loast Common Mulipicant), ir LOM solo: Pinclude void main() int x,y,ilarge,lem; printf("LCM = %d\n",lem); } scanf("hd%d",&x,8y); { if(xemy) lemex; int msrt.left,right.lsrt rst; else for(n=1000; n<=9999;n++) { { if(x>yB&x%yan0) srtesqrt(n); lemex; if(stt*srt==n) if(y>x&By%oxem0) { lcmay; right=n%100; ‘if(x%y!-088y%x!=0) leften/100; { Isrtesqrt(right); large = (xey2xy); Lsrtasqrt(left); for(inlarge+tzi Hinclude void main() Solr ¥ include #includecmath.h> void main() Program 3.6.63 ae isum,n; Pie a program that finds all perfect squares between 1 fo ane on oe sum=0; com forliet;icen;it+) # include { include sum=sumsi; void main() } { printf("Sum = %d\n",sum); int n, srt; } for(n=1;n<91000;n+4) ba nent ) Program 3.8.66 srtesqrt(n); Write a program to calculate x +x? + x3 + if(srt*srte=n) Soin. ‘ printf("%d\n".n); # include 5 } fincludecmath.h> Scanned with CamScanner } rintf("Sum = %F\n",sum); } Wit a program to caleuate x42 + sum=sumspow(x,i) i | " Program 3.6.67 ¢ } Soin. : Program 3.6, Write a program to calculate x +35 # include include void main() float x,n,i,sum; scanf("%f%f", &x,8n); sums0; for(ist;ican;i++) { } printf("Sum = %4f\n",sum); sumesum+pow(s,i)/i: ¥ * { # include #include void main() float fact.x,n,i,sum; scanf(“f%f",&x,8n); facte sum=0; for(iet;ic=nsi++) { factefact*i; sumesum+pow(x,i)/fact; } printf("Sum = %f\n" sum); Program 3.6.69 waite a program to calculate Se ee SS) q include ginclude void main() { float fact.x-n,i,sum scanf("4F%F* 8,80): sum=0; factel; for(iels icon: xx Pee: int) factefact*i: f sumasums(-1)*(pow(-x.i)/fact); } . printf(*Sum = ‘bF\n" sum); | ) Rene | Program 3.6.70 5 Sol oe ee eee # include Hincludecmath.h> void main() { float fact,x,n,,j,sum; scanf("%f9f",8x,8n); sum=0; siceninit2) factefact*j; } sum=sumspow(x,i) fact; } printf(*Sum =9%F\n",sum); ; : Program 3.6.71 Write a program ASCII values. include void main() that daplays all the charactors and tt! Scanned with CamScanner nsigned char x: wed: while(x<255) printf("%C%A\N"yX,3); xe } printf("%c %ed\N".x); ge —_——____} > program 3.6.72 ‘a program to display the following pattem up to a given et. include void main() { char x.y.Z.p? | Ftush(stdin); | scanf(*s%c" 8x); | yoxetoupper(x): ABCDEF for(2Asze=xiz++) ABCDE { ABCD | for(peAipeyips) ABC | { AB | printf("4ec"p); A | } | printf("\n"); | yo | + bo ¥ Program 3.6.73 Write a program to display the following pattem up 10 the ven alphabet | # include { printf("%c",p); } printf("\n"); [Se ) ener eeeeene ee Program 3.6.74 ‘Write a program to dsplay the folowing patter. Soln. : # include void main() o { . int mij: a printf("Enter number of rows\n"); **** seanf("%ed" &n); COG forliel;icansit+) { printf(\n")s } } Program 3.6.75 ‘Write @ program to display the following pattem. Soin. : # include void main( ) t int n.m,i, printf("Enter number of rows\n"); scanf("%ed",8n); for(ietiicensit+) void main() forljetsiems++) ae ( { es char x,2.P3 printf? *)s . | fflush(stdin); scanf("%c" 8%); AB | xetoupper(x); ABC | for(ze'Aiz—=xi24) ABCD ; | { ABCDE L for(p='Aipe=zipt+)_ A BCDEF } Scanned with CamScanner BF asic Computer Programming (Or. BATU) Program 3.6.76 Write @ program to Given number : 1 22 333 4444 55555 Soln.: # include void main() Produce the following output, upto the int ijn; scanf("%d", &in); printf(" %d "i; printf("\n"); } Program 3.6.77 Write a program to produce the following output, upto the given number: 3:29 fp Program 3.6.78 Wea program to generate and cisPlay Pascal lang, lea. 1 31 e644 10 1051 2 3 4 5 # include Jf Program 3.6.79 void main() { int ij, m5 scanf("%ed", &n); printf(" %d ",j); } printf("\n"); Write a program to generate the Floyd's triangle. Solr # include void main( ) { int njm,i,j; brintf("Enter a number\n*); scanf("4ed",&n); m=; j=; while(me=n) 23 fa 456 forlintzicajsiee) 78910 { Scanned with CamScanner } printf("\n"); ju |) ee ema yp Program 3.6.60 ate a program to generate the following pattern soln 1 void main( ) 01 { 101 int nm kj 0101 printf("Enter how many rows\n"); 10101 scanf("%bd*,&n); m= for(iml;icen;it+) { kam; for(imt5 { jemirjt4) printf(*%2d",k); ketk; } me!m; printf("\n"); } > Program 36.81 Two numbers are entered through the keyboard. Write a program to find the value of one number raised tothe power of anther. (Do not use library function) Soln,: Soins # include | void main( ) { int x,y, <1; long int power = 1; printf("Enter two numbers:"); scanf("%ed°%ed", Bx, 8y); while(icay) { Powerepower*x; iss; ) printf(*\n'hd to the power ‘isetild" x.y, pow J Hf Program 3.6.02 Write program to produce the flowing output ABCDEFGFEDCBA ABCDEF FEDCBA ABCDE EOCBA ABco ocBA ABC cea AB BA A A Sol #include-stdio.h> void main() {int iet,x=7,blankse0,j,val.k: "ted while(icn7) { 5x65; val = x: while(jcnval) { printf("*6c", ini while(kesblanks) { printf(” *); ke; } blanks=2*i-1; while(val>=65) \n\nPress any key to © Lies Scanned with CamScanner

You might also like