Download as pdf
Download as pdf
You are on page 1of 14
CONTENTS S.NO NAME OF THE EXPERIMENTS PAGE NO Write a C Program to generate first ‘n’ terms of the Fibonacci 1 | sequence 2 | Write a C Program to generate prime numbers between 1 and ‘n’ Write a C Program to find the Factorial using recursion and non- 3° | recursion 4 _ | Write aC Program to find the GCD of two given positive numbers Write aC Program to perform the arithmetic operations on two 5 | numbers using switch statement Write a C Program to find the sum of series (1-x?/2! +x4/4!- 6 | x6/61+x8/8!-x!°/10!) Write aC Program to implement the addition of ‘n’ numbers in an 7 | anay Write a C program to find both the largest and smallest number in a 8 | list of integers after arranging them in ascending order 9 | Write a C Program to merge two sorted arrays 10 | Write a C Program to find the given string is Palindrome or not. Write aC Program that uses the concept of function 1. Write a € Program to generate first ‘n’ terms of the Fibonacci sequence Aim: To write a C program fo generate first ‘n’ terms of the Fibonacci sequence Algorith Step 1: Initialize the required variables Step 2: Perform the calculation while(count void main() { int fib1 = 0, fib2 = 1, fib3, num, count printf("Enter the value of num \n") scanf("96d", &entum), print{("First %d FIBONACCI numbers are ..\n", num); print{("%ad\n", fib1); rintf(*%6d\n", fib2); count = 2; /* fib and fib2 are already used */ while (count'< num) t fib3 = fibl + fib2: counts; printf("%edw", fib3); fib] = fib2; fib2 = fib3; I 4 Output: Enter the value of num 15 First 15 FIBONACCI numbers are ... wuunere PSNCET - $01102- Computer Lab Manual Result : Thus the program was verified and output executed successfully. 2. Write a C Program to generate prime numbers between 1 and ‘n’ Al To Write aC Program to generate prime numbers between | and ‘n* Algorithi Step 1: Initialize the required variables Step 2: Use for loop from I to n to check the condition Step 3: If satisfied the condition to get the factorial of a number Step 4: Print the result Program: #include int main(){ int mum,,count.n; printi("Emter max range: "); count = 0; for(i=2;i<=num/2; if(count==0 && num!= 1) printf("¥%d } return 0; Output: Enter max range: 50 23571113 Result : Thus the program was verified and output executed successfully. 3. Write a C Program to find the Factorial using recursion and non-recursion, Aim: To Write a C Program to find the Factorial using recursion and non-recursion Algorithm: Step I: Start Step 2: Read number n Step 3: Call factorial(n) Step 4; Print factorial f Step 5: Stop Factorial(n) Step 1: Ifn—=1 then return 1 Step 2: Else fn*factorial(n-!) Step 3: Retum£ Program: ‘include include void main() t int, a,b; clrser(): printf("Enter any number\n"); scanf("%d", &n); a= reefactorial(a); printf("The factorial ofa given number using recursion b=nonrecfactorial(n): print{("The factorial of a given number using nonrecursion is %d", b}: getch(); ) int recfactorial(int x) { d\n", a); £=x * recfactorial(x - 1); return); ) int nonrecfactorial(int x) { inti, f= 1s forli= Lei xsi) fafti ) feats Output: Enter any number 5 ‘The factorial ofa given number using recursion is 120 ‘The factorial ofa given number using nonrecursion is 120 Result ‘Thus the program was verified and output executed successfully. 4.Write a C Program to find the GCD of two given positive numbers Aim: To Write a C Program to find the GCD of two given positive numbers Algorithm: Step 1: Start the program Step 2: initialize the two positive numbers Step 3: check whether the nl>n2 Step 4: Assign nl=n2 Step 5: Else the n2 =nl Step 4: Finally get the GCD of two positive numbers Step 5: Stop the program Program: #include int main() { int nl, n2; print{("Enter two positive integers: scanf("%d %d" dnl &n2); while(nl!=n2) t iffal > 12) nl =n2; else n2-=nl; 3 printf("GCD = %d".n1); return 0; } Output: Enter two positive integers: 81 153 GCD=9 Result : Thus the program was verified and output executed successfully. 5. Write a C Program to perform the arithmetic operations on two numbers using switch statement Aim: To Write a program for to perform the arithmetic operations on two numbers using switch statement Algorithm: Step 1: Start the program Step 2: initialize the two positive numbers Step 3: perform the arithmetic calculation using switch concept Step 4: Finally get the result Step 5: Stop the program Program #include #include int main) printf(" 1.Addition\n 2.Subtraction\n 3. Multplication\n 4.Division\n”) print{("Eater the values of a & b: "; scanf{"%d %d",&a,éb); print{("Enter your Choice scanft"%d", op); switch(op) ‘ case 1: printf("Sum of %d and 96d is : %d".a,b,a+b); breals case 2: printf("Difference of %d and %d is : %d".a,b.a-b): break: case 3: printf("Multiplica break: case 4: jon of %d and %d is : %6d",a,b,a*b); LAddition 2Subtraction 3.Multiplication 4Division Enter the values of a & b: 20 15 Enter your Choi ‘Sum of 20 and 15 is : 35 Result : ‘Thus the program was verified and output executed successfully. 6. Write a C Program to find the sum of series (1-x2/2! +3'/41-x6/614x8/8!-x19/101) Aim: ‘To Write a program to find the sum of series (1-2/2! +x1/4!-x9/6!+x9/8!-x!°/10!) Algorithm: Step 1: Start the program Step 2: initialize the two positive numbers Step 3: perform the sum of series using for loop Step 4: Perform the calculation tHt*(-1)*x*/i*(iel)s soset; Step 5: Finally get the result and print the sum result ‘Step 6: Stop the program Prog #include int main() t float x,i,t,s=1; printf(“Enter x value : scanit%f",&x); ttt *xtwi"(iel); printf("X = %fin".x); printf("t = fin } printf“Result = %fin"s); return 0; J Output Enter x value: 10 Result = -1296.795532 Result : ‘Thus the program was verified and output executed successfully. 7. Write a C Program to implement the addition of ‘n° numbers in an array Alm: ‘Write a C Program to implement the addition of ‘n’ numbers in an array tart the program Step 2: initialize the two positive numbers Step 3: perform the addition of n arrays using for loop Step 4: Finally get the result and print the result Step 5: Stop the program Program: include int main() { printi(*\n\n\t\tStudytonight - Best place to leamw\n\n"): int n, sum = 0, c, array 100]; printi("Enter the number of integers you want to add: scanft"%d", &n); printi(*\ninEnter 9d integers \nln", n); fore = 0;¢ void main () int i,j. a, n, counter, average; print{("Enter the value of Nin"): seanfi"%d", Sn): printi("Enter the numbers \n"); for (i= O:i- int mainQ) { int nt.n2.n3; printf("\nEnter the size of first array "); soanf("¢ed",éenl); printf("\nEnter the size of second array "); scanf{"%6d",Sn2); n3=nl+n2; printf("\nEnter the sorted array elements”) int afnt}.b{n2},c(n3): //Arrey Declaration for(int i=Ocicnlsi++) Array Initialized t seanf("96d" Sali); iret int ken; printf("\nEnter the sorted array elements"); fortint i-0;i #include int main() { char string! [20]; inti, length: int flag = printf("Enter a string: seanf{"96s", string! length = strlen(string1); if flag) { printi("%s is not a palindrome”, stringl); else { printf("%s isa palindrome”, string1); return 0; } Output: Enter the string: WOW WOW is a palindrome Result : ‘Thus the program was verified and output executed successfully. ee EE ee 11, Write a C Program that uses the concept of function Aim: 12 ‘To Write a C Program that uses the concept of function Algorithm: Step 1: Start the program Step 2: get the values for two numbers Step 3: perform the area of the rectangle with length and width values using function concept Step 4: Finally get the result and print the result Step 5: Stop the program Progra #include /# function declaration float find Area(Hloat 1, float b); int main() { Mloat length, width, result; print{("Enter the length and width of the rectangle: "), scanf("af %f", Sclength, &width); result = findArea(length, wid printi("Area of rectang! return 0; ‘function calling 2fn" result); // fanction to find ara of rectangle // fanetion definition float findArea(float |, float b) { float area; area=1* bs return area; //return statement Ontput: Enter the length and width of the rectangle: 12.5,5 Area of rectangle: 62.50 Result : Thus the program was verified and output executed successfully. B

You might also like