Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

‭FIBONACCI SERIES‬

‭ARMSTRONG NUMBER‬
‭ .‬
1
‭Call by value in C‬
‭2.‬ ‭ include<stdio.h>‬
#
‭3.‬ ‭int‬‭main()‬ ‭ include<stdio.h>‬
#
‭4.‬ ‭{‬ ‭int‬‭main() {‬
‭ In call by value method, the value of‬
#
‭5.‬ ‭int‬‭n1=0,n2=1,n3,i,number;‬
‭the actual parameters is copied into‬
‭6.‬ ‭printf(‬‭"Enter the number of‬ ‭ .‬
1 i‭nt‬‭n,r,sum=0,temp;‬
‭the formal parameters. In other words,‬
‭elements:"‬‭);‬ ‭2.‬ ‭printf(‬‭"enter the number="‬‭);‬
‭we can say that the value of the‬
‭7.‬ ‭scanf(‬‭"%d"‬‭,&number);‬ ‭3.‬ ‭scanf(‬‭"%d"‬‭,&n);‬
‭variable is used in the function call in‬
‭8.‬ ‭printf(‬‭"\n%d %d"‬‭,n1,n2);‬‭//printing 0‬ ‭4.‬ ‭temp=n;‬
‭the call by value method. #In call by‬
‭and 1‬ ‭5.‬ ‭while‬‭(n>0)‬
‭value method, we can not modify the‬
‭9.‬ ‭for‬‭(i=2;i<number;++i)‬‭//loop starts‬ ‭6.‬ ‭{‬
‭value of the actual parameter by the‬
‭from 2 because 0 and 1 are already‬ ‭7.‬ ‭r=n%10;‬
‭formal parameter.‬
‭printed‬ ‭8.‬ ‭sum=sum+(r*r*r);‬
‭#In call by value, different memory is‬
‭10.‬ ‭{‬ ‭9.‬ ‭n=n/10;‬
‭allocated for actual and formal‬
‭11.‬ ‭n3=n1+n2;‬ ‭10.‬ ‭}‬
‭parameters since the value of the‬
‭12.‬ ‭printf(‬‭" %d"‬‭,n3);‬ ‭11.‬ ‭if‬‭(temp==sum)‬
‭actual parameter is copied into the‬
‭13.‬ ‭n1=n2;‬ ‭12.‬ ‭printf(‬‭"armstrong number "‬‭);‬
‭formal parameter. #The‬
‭14.‬ ‭n2=n3;‬ ‭13.‬ ‭else‬
‭actual parameter is the argument‬
‭15.‬ ‭}‬ ‭14.‬ ‭printf(‬‭"not armstrong‬
‭which is used in the function call‬
‭16.‬ ‭return‬‭0;‬ ‭number"‬‭);‬
‭whereas formal parameter is the‬
‭17.‬ ‭}‬ ‭15.‬ ‭return‬‭0;‬
‭argument which is used in the function‬
‭Enter the number of elements:15‬
‭definition.‬ ‭ 6.‬ ‭}‬
1 ‭Recursion in C‬
‭0 1 1 2 3 5 8 13 21 34 55 89 144 233 377‬
‭ ecursion‬ ‭is‬ ‭the‬ ‭process‬ ‭which‬ ‭comes‬ ‭into‬
R
‭existence‬ ‭when‬ ‭a‬ ‭function‬ ‭calls‬‭a‬‭copy‬‭of‬‭itself‬‭to‬
‭PRIME NUMBER‬ ‭#include<stdio.h>‬ ‭work‬ ‭on‬ ‭a‬ ‭smaller‬ ‭problem.‬ ‭Any‬ ‭function‬ ‭which‬
‭calls‬ ‭itself‬ ‭is‬ ‭called‬ ‭recursive‬ ‭function,‬ ‭and‬ ‭such‬
‭ .‬
1 ‭ include<stdio.h>‬
# ‭function‬ ‭calls‬ ‭are‬‭called‬‭recursive‬‭calls.‬‭Recursion‬
‭ .‬
1 ‭void‬‭change(‬‭int‬‭num) {‬
‭2.‬ ‭int‬‭main(){‬ ‭17.‬ ‭involves‬ ‭several‬ ‭numbers‬ ‭of‬ ‭recursive‬ ‭calls.‬
‭2.‬ ‭printf(‬‭"Before adding‬
‭3.‬ ‭int‬‭n,i,m=0,flag=0;‬ ‭However,‬ ‭it‬ ‭is‬ ‭important‬ ‭to‬ ‭impose‬ ‭a‬ ‭termination‬
‭value inside function‬ ‭PALINDROME PROGRAM‬
‭4.‬ ‭printf(‬‭"Enter the number to check‬ ‭condition‬ ‭of‬ ‭recursion.‬ ‭Recursion‬ ‭code‬ ‭is‬ ‭shorter‬
‭num=%d \n"‬‭,num);‬
‭ .‬
1 ‭ include<stdio.h>‬
# ‭than‬ ‭iterative‬ ‭code‬ ‭however‬ ‭it‬ ‭is‬ ‭difficult‬ ‭to‬
‭prime:"‬‭);‬ ‭3.‬ ‭num=num+100;‬
‭2.‬ ‭int‬‭main()‬ ‭understand.‬‭Recursion‬‭cannot‬‭be‬‭applied‬‭to‬‭all‬‭the‬
‭5.‬ ‭scanf(‬‭"%d"‬‭,&n);‬ ‭4.‬ ‭printf(‬‭"After adding value‬
‭3.‬ ‭{‬ ‭problem,‬ ‭but‬ ‭it‬ ‭is‬ ‭more‬ ‭useful‬ ‭for‬ ‭the‬ ‭tasks‬ ‭that‬
‭6.‬ ‭m=n/2;‬ ‭inside function num=%d‬
‭4.‬ ‭int‬‭n,r,sum=0,temp;‬ ‭can‬ ‭be‬ ‭defined‬ ‭in‬ ‭terms‬ ‭of‬ ‭similar‬ ‭subtasks.‬ ‭For‬
‭7.‬ ‭for‬‭(i=2;i<=m;i++)‬ ‭\n"‬‭, num);‬
‭5.‬ ‭printf(‬‭"enter the number="‬‭);‬ ‭Example,‬ ‭recursion‬ ‭may‬ ‭be‬ ‭applied‬ ‭to‬ ‭sorting,‬
‭8.‬ ‭{‬ ‭5.‬ ‭}‬
‭6.‬ ‭scanf(‬‭"%d"‬‭,&n);‬ ‭searching, and traversal problems.‬
‭9.‬ ‭if‬‭(n%i==0)‬ ‭6.‬ ‭int‬‭main() {‬
‭7.‬ ‭temp=n;‬
‭10.‬ ‭{‬ ‭7.‬ ‭int‬‭x=100;‬
‭8.‬ ‭while‬‭(n>0)‬
‭11.‬ ‭printf(‬‭"Number is not prime"‬‭);‬ ‭8.‬ ‭printf(‬‭"Before function‬
‭9.‬ ‭{‬
‭12.‬ ‭flag=1;‬ ‭call x=%d \n"‬‭, x);‬
‭10.‬ ‭r=n%10;‬
‭Recursive‬‭Function:-‬ ‭A‬‭recursive‬‭function‬
‭13.‬ ‭break‬‭;‬ ‭9.‬ ‭change(x);‬‭//passing‬ ‭ erforms‬ ‭the‬ ‭tasks‬ ‭by‬ ‭dividing‬ ‭it‬ ‭into‬ ‭the‬
p
‭11.‬ ‭sum=(sum*10)+r;‬
‭14.‬ ‭}‬ ‭value in function‬ ‭subtasks.‬ ‭There‬‭is‬‭a‬‭termination‬‭condition‬‭defined‬
‭12.‬ ‭n=n/10;‬
‭15.‬ ‭}‬ ‭10.‬ ‭printf(‬‭"After function call‬ ‭in‬ ‭the‬ ‭function‬‭which‬‭is‬‭satisfied‬‭by‬‭some‬‭specific‬
‭13.‬ ‭}‬
‭16.‬ ‭if‬‭(flag==0)‬ ‭x=%d \n"‬‭, x);‬ ‭subtask.‬ ‭After‬ ‭this,‬ ‭the‬ ‭recursion‬ ‭stops‬ ‭and‬ ‭the‬
‭14.‬ ‭if‬‭(temp==sum)‬
‭17.‬ ‭printf(‬‭"Number is prime"‬‭);‬ ‭ 1.‬ ‭return‬‭0;‬
1 ‭final‬ ‭result‬ ‭is‬ ‭returned‬ ‭from‬ ‭the‬ ‭function.‬ ‭The‬
‭15.‬ ‭printf(‬‭"palindrome number "‬‭);‬
‭18.‬ ‭return‬‭0;‬ ‭12.‬ ‭}‬ ‭case‬ ‭at‬ ‭which‬ ‭the‬ ‭function‬ ‭doesn't‬ ‭recur‬ ‭is‬‭called‬
‭16.‬ ‭else‬
‭19.‬ ‭}‬ ‭the‬ ‭base‬ ‭case‬ ‭whereas‬ ‭the‬ ‭instances‬ ‭where‬ ‭the‬
‭Before function call x=100‬ ‭17.‬ ‭printf(‬‭"not palindrome"‬‭);‬
‭Enter the number to check prime:56‬ ‭function‬ ‭keeps‬ ‭calling‬ ‭itself‬ ‭to‬‭perform‬‭a‬‭subtask,‬
‭ efore adding value inside function‬
B ‭18.‬ ‭return‬‭0;‬
‭Number is not prime‬ ‭is‬ ‭called‬ ‭the‬ ‭recursive‬ ‭case.‬ ‭All‬ ‭the‬ ‭recursive‬
‭num=100‬ ‭19.‬ ‭}‬
‭functions can be written using this format.‬
‭ nter the number to check prime:23‬
E ‭ fter adding value inside function‬
A
‭Number is prime‬ ‭num=200‬
‭After function call x=100‬ ‭ .‬
1 ‭ include<stdio.h>‬
#
‭Sum of digits‬ ‭2.‬ ‭int‬‭fibonacci(‬‭int‬‭);‬
‭3.‬ ‭void‬‭main ()‬
‭ .‬
1 ‭#include<stdio.h>‬ ‭Call‬ ‭By‬ ‭Reference‬ ‭in‬ ‭C‬ ‭4.‬ ‭{‬
‭2.‬ ‭int‬‭main()‬ ‭5.‬ ‭int‬‭n,f;‬
‭#In‬ ‭call‬ ‭by‬ ‭reference,‬ ‭the‬ ‭address‬ ‭of‬ ‭ ACTORIAL OF NUMBER‬
F
‭3.‬ ‭{‬ ‭6.‬ ‭printf(‬‭"Enter the value of n?"‬‭);‬
‭4.‬ ‭int‬‭n,sum=0,m;‬ ‭the‬ ‭variable‬ ‭is‬‭passed‬‭into‬‭the‬‭function‬ ‭#include<stdio.h>‬ ‭7.‬ ‭scanf(‬‭"%d"‬‭,&n);‬
‭5.‬ ‭printf(‬‭"Enter a number:"‬‭);‬ ‭call‬ ‭as‬ ‭the‬ ‭actual‬ ‭parameter.‬ ‭ .‬
1 i‭nt‬‭main()‬ ‭8.‬ ‭f = fibonacci(n);‬
‭6.‬ ‭scanf(‬‭"%d"‬‭,&n);‬ ‭2.‬ ‭{‬ ‭9.‬ ‭printf(‬‭"%d"‬‭,f);‬
‭#The‬ ‭value‬ ‭of‬ ‭the‬ ‭actual‬ ‭parameters‬
‭7.‬ ‭while‬‭(n>0)‬ ‭3.‬ ‭int‬‭i,fact=1,number;‬ ‭10.‬
‭}‬
‭8.‬ ‭{‬ ‭can‬ ‭be‬ ‭modified‬ ‭by‬ ‭changing‬ ‭the‬ ‭11.‬
‭int‬‭fibonacci (‬‭int‬‭n)‬
‭4.‬ ‭printf(‬‭"Enter a number: "‬‭);‬
‭9.‬ ‭m=n%10;‬ ‭formal‬ ‭parameters‬ ‭since‬ ‭the‬ ‭address‬ ‭5.‬ ‭scanf(‬‭"%d"‬‭,&number);‬ ‭12.‬
‭{‬
‭10.‬ ‭sum=sum+m;‬ ‭of‬ ‭the‬ ‭actual‬ ‭parameters‬ ‭is‬ ‭passed.‬ ‭6.‬ ‭for‬‭(i=1;i<=number;i++){‬ ‭13.‬ ‭if‬‭(n==0)‬
‭11.‬ ‭n=n/10;‬ ‭7.‬ ‭fact=fact*i;‬ ‭14.‬ ‭{‬
‭12.‬ ‭}‬ ‭#In‬ ‭call‬ ‭by‬ ‭reference,‬ ‭the‬ ‭memory‬ ‭15.‬ ‭return‬‭0;‬
‭8.‬ ‭}‬
‭13.‬ ‭printf(‬‭"Sum is=%d"‬‭,sum);‬ ‭allocation‬ ‭is‬ ‭similar‬ ‭for‬ ‭both‬ ‭formal‬ ‭9.‬ ‭printf(‬‭"Factorial of %d is:‬ ‭16.‬ ‭}‬
‭14.‬ ‭return‬‭0;‬ ‭parameters‬ ‭and‬ ‭actual‬ ‭parameters.‬‭All‬ ‭%d"‬‭,number,fact);‬ ‭17.‬ ‭else‬‭if‬‭(n == 1)‬
‭15.‬ ‭}‬ ‭10.‬ ‭return‬‭0;‬ ‭18.‬ ‭{‬
‭the‬ ‭operations‬ ‭in‬ ‭the‬ ‭function‬ ‭are‬
‭Enter a number:654‬ ‭ 1.‬ ‭}‬
1 ‭19.‬ ‭return‬‭1;‬
‭Sum is=15‬ ‭performed‬ ‭on‬ ‭the‬ ‭value‬ ‭stored‬ ‭at‬ ‭the‬ ‭20.‬ ‭}‬
‭address‬ ‭of‬ ‭the‬ ‭actual‬ ‭parameters,‬ ‭and‬ ‭21.‬ ‭else‬
‭ nter a number:123‬
E ‭Output:‬ ‭22.‬ ‭{‬
‭the‬ ‭modified‬ ‭value‬ ‭gets‬ ‭stored‬ ‭at‬ ‭the‬
‭Sum is=6‬ ‭23.‬ ‭return‬
‭same address.‬ ‭Enter a number: 5‬ ‭fibonacci(n-1)+fibonacci(n-2);‬
‭24.‬ ‭}‬
‭Factorial of 5 is: 120‬ ‭ 5.‬ ‭}‬
2

You might also like