Lab Question - Bhupendra Saud
Lab Question - Bhupendra Saud
13. Write a program to find the roots of a quadratic equation. Read coefficients from the users
and checks imaginary and real root.
1
Bhupendra saud
14. Differentiate between if….else and switch statements. Write a program that masks an
arithmetic operator and two operands and performs the corresponding operation on the
operands.
15. Write a program to find the value of y by reading value of x from the users by using
conditional operator.
2x+300 for x<50
Y = 200 for x=50
50x-100 for x>50
[Hint: y=(x!=50)?((x<50)?(2x+300):(50x-100)):200]
16. Why repetitive statements (loop) are used? List looping statements. Write a program to find
the multiplication of two numbers without using multiplication operator.
[Hint: using repetitive addition]
17. Write a program to find whether given number is prime or composite.
18. Write a program to find the sum of first n-natural numbers and then find average.
19. Write a program to read two integers n1 and n2. And display all even numbers between
those two numbers.
20. What is nested loop? Explain use of break and continue statements. Write a program to
print the prime numbers between 1 to 100.
21. Write a program to find HCF of any two numbers.
Hint:
Read a, b
do
{
r=a%b;
if(r==0)
printf(“HCF=%d”,b);
else
{
a=b;
b=r;
}
}while(r!=0);
2
Bhupendra saud
22. Write a program to find the sum of the digits of given number.
Hint:
While (n>0)
{
R=n%10;
S=S+R;
n/=10;
}
23. Write a program to find the products of the digits of any number.
24. Write a program to find reverse of given number.
25. Write a program to find whether a given number is palindrome or not.
26. Write a program to find binary equivalent of given decimal number.
Hint:
Read n
Base=1;
s=0;
while (n!=0)
{
R=n%2; s=s + r * base; base=base*10; n=n/2;
}
27. Write a program to convert the given binary number to its equivalent decimal number.
Hint:
Read n
J=1;
Dec=0;
While(n>0)
{
R=n%10;
Dec=Dec+r*j;
n/=10;
}
Print dec
28. Write a program to find whether given number is Armstrong number or not.
Hint: [371 is Armstrong number because 371=3 3+73+13=371]
29. Write a program to display Armstrong numbers between 100 to 1000.
30. Write a program to find sum of the square of all odd numbers from 1 to 100.
31. Write a program to find the factorial of given number.
32. Write a program to display the Fibonacci series (0, 1, 1, 2, 3, 5, 8, 13, 21, ……..) Read nth
term from the user using iteration.
Hint:
Read n
First=0;
Second=1;
While (term<n)
{
3
Bhupendra saud
36. Write a program to print the following pattern using nested loops.
*
* *
* * *
* * * *
* * * * *
37. Write a program to print the following pattern using nested loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
38. Write a program to print the following pattern (Floyd’s Triangle) using nested loops
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
40. Write a program to find the terms in the given series till the term value is less than 250
(12+22)/3, (22+32)/4, (32+42)/5, ………………………
Hint:
Term=0; i=1;
While(term<250)
{
Term=((i*i)+(i+1)*(i+1))/((float)(i+2));
Print Term;
i++;
}
41. Write a program to compute the following series (Euler’s number series)
1+ 1/1! + 1/2! + 1/3! +……………………+ 1/n!
Read n from user
5
Bhupendra saud