Department of Computer Science and Engineering
C Lab

1.Write a C Program to find all roots of a quadratic equation ax2+bx+c=0?

Algorithm :
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
         D←b2-4ac
Step 4: If D≥0
              r1←(-b+√D)/2a
              r2←(-b-√D)/2a
              Display r1 and r2 as roots.
        Else
              Calculate real part and imaginary part
              rp←b/2a
              ip←√(-D)/2a
              Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop  

Sample Output:
Enter the values of a,b,c
1 -5 6
The roots of a quadratic equation are :
2,3
Code Here

2.Write a C Program to find the Fibonacci series till term≤1000?

Algorithm :
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term≤1000
     5.1: temp←second_term
     5.2: second_term←second_term+first term
     5.3: first_term←temp
     5.4: Display second_term
Step 6: Stop

Sample Output:
fibonacci series is 0 1 1 2 3 5 8..............377 610 987
Code Here

3.Write a C Program to insert an element in an array in the given position?

Algorithm :
Step 1: Start
Step 2: Enter the size of the array
Step 3: Enter the elements of array
Step 4: Enter the element to be inserted and its position in the array
Step 5: Set a loop up to position you enter
Step 6: Push the otherof the position by one,which are greater,then the position you entered
Step 7: Display the array after the insertion
Step 8: Stop

Sample Output:
Enter the size of array
5
Enter the elements of the array
1 2 4 5 6
Enter the element and its position in the array
3 3
Array after the insertion
1 2 3 4 5 6
Code Here

4.Write a C Program to binary number into decimal number?

Algorithm :
Step 1: Start
Step 2: Enter the binary value
Step 3: set a loop
Step 4: convert the binary number to decimal by using the given statement
		find the digit
		decimal=decimal+(digit<<_base);
		base=base+!;
		binary number=binarynumber/10;
Step 5: After the execution of the loop print the decimal value equivalent to the entered binary number
Step 6: Stop

Sample Output:
Enter the binary number...100
The binary equivalent of 100 in decimal = 4
Code Here

5.Write a C Program to Find cosine value of X?

Algorithm :
Step 1: Start
Step 2: Enter the value of X
Step 3: Convert X into Radian
Step 4: Set a loop
		Find the value of cosine using the formula
		temp=temp*pow((double)(-1),(double)(2*i-1))*x*X/(2*i*(2*i-1);
		sum=sum+temp;
Step 5: After the execution of the loop print the cosine value;
Step 6: Stop

Sample Output:
Enter the value of X
30
The value of cos(x)=0.866
Code Here

More programs will be uploaded soon...