Posts

Showing posts from April, 2022

10. Write a program to find the sum of following series 1-X1/1!+X2/2!- ............Xn/n!.

 SOURCE CODE: #include <stdio.h> #include <math.h> int fac( int n) {   if (n== 0 || n== 1 )     return 1 ;     else return n*fac(n- 1 ); } int main() {   int i,n,x;     float sum= 1 ,c;     printf( "enter the value of x and n\n" );     scanf( "%d %d" ,&x,&n);     for (i= 1 ;i<=n;i++)     {  c=(pow(-x,i)/fac(i));        sum+=c;     }     printf( "value of given series is %f" ,sum);     return 0 ; }

9. Write a program to generate sum of series 1!+2!+3!+--------------n!

 SOURCE CODE: Method 1... #include <stdio.h> int fact_sum( int n) {   int i,c;     int sum= 0 ,f= 1 ;     for (i= 1 ; i<=n;i++) {     f= f*i;     sum+=f;     printf( "%d!" ,i);     if (n!=i){         printf( "+" );     }     }     return sum; } int main() {   int n,c;     printf( "enter the value of n\n" );     scanf( "%d" ,&n);     printf( "=%d" ,fact_sum(n));     return 0 ; } Method 2... #include <stdio.h> int fact( int n) { if (n== 1 || n== 0 )   return 1 ;   else   return n*fact(n- 1 ); } int fact_sum( int n) {   int i,c;     int sum= 0 ;     for (i= 1 ; i<=n;i++) {     c= fact(i);     sum+=c;     }     return sum; } int main() {   int n,c;     printf( "enter the value of n\n" );  ...

8. Write a program to find whether the number is Armstrong number.

 SOURCE CODE: include <stdio.h> int main() {   int num,rem,res= 0 ,real_num;     printf( "enter a number\n" );     scanf( "%d" ,&num);     real_num=num;     while (real_num!= 0 ){     rem=real_num% 10 ;     res+=rem*rem*rem;     real_num/= 10 ;     }       if (num==res)      { printf( "%d is an armstrong number" ,num); }       else      printf( "%d is not an armstrong number" ,num);     return 0 ; }

7. Write a program to construct a Fibonacci series upto n terms.

 SOURCE CODE: #include <stdio.h> int main() {   int t1= 0 ,t2= 1 ,n,next_term;     printf( "enter how many terms you want\n" );     scanf( "%d" ,&n);     printf( "%d,%d," ,t1,t2);     next_term=t1+t2;     for ( int i= 3 ;i<=n;i++)     {  printf( "%d," ,next_term);        t1=t2;        t2=next_term;        next_term=t1+t2;     }     return 0 ; }

6. Write a program to find the value of y for a particular value of n. The a, x, b, n is input by user if n=1 y=ax%b if n=2 y=ax2+b2 if n=3 y=a-bx if n=4 y=a+x/b

 SOURCE CODE: Using nested if else: #include <stdio.h> int main() {   int a,x,b,n;     float y;     printf( "enter the value of a,x,b,n\n" );     scanf( "%d %d %d %d" ,&a,&x,&b,&n);     if (n== 1 )     { y=(a*x)%b; }     else if (n== 2 ){         y=a*x*x+b*b;     }     else if (n== 3 )     { y=a-b*x; }     else if (n== 4 ){       y=a+(x/b);         }     printf( "value of y is %f" ,y);         return 0 ; } Using switch case: #include <stdio.h> int main() {   int a,x,b,n;     float y;     printf( "enter the value of a,x,b,n\n" );     scanf( "%d %d %d %d" ,&a,&x,&b,&n);     switch (n)     { case 1 :       y=(a*x)%b;       printf( "y=%f" ,y);     ...

5. Write a program to receive marks of physics, chemistry & maths from user & check its eligibility for course if a) Marks of physics > 40 b) Marks of chemistry > 50 c) Marks of math’s > 60 d) Total of physics & math’s marks > 150 or e) Total of three subjects marks > 200

 SOURCE CODE: #include <stdio.h> int main() {   float p,c,m;     printf( "enter the marks of physics, chemistry and maths\n" );     scanf( "%f %f %f" ,&p,&c,&m);     if ((p> 40 && c> 50 && m> 60 && (p+m)> 150 ) || ((p+c+m)> 200 ))     printf( "eligible for course" );     else     printf( "not eligible for course" );     return 0 ; }

4. Write a program to find the largest of three numbers using nested if else

 SOURCE CODE: #include <stdio.h> int main() {   float a,b,c;     printf( "enter three numbers\n" );     scanf( "%f %f %f" ,&a,&b,&c);     if (a>b)     {   if (a>c)         printf( "%f is greatest" ,a);         else        printf( "%f is greatest" ,c);     }     else     { if (b>c)        printf( "%f is greatest" ,b);       else       printf( "%f is greatest" ,c);     }         return 0 ; }

3. Write a program to determine the roots of quadratic equation

 SOURCE CODE: #include <stdio.h> #include <math.h> int main() {   float a,b,c,D,x,y;     printf( "enter the coefficients of quadratic equation\n" );     scanf( "%f %f %f" ,&a,&b,&c);     D=(b*b- 4 *a*c);     x=(-b+sqrt(D))/( 2 *a);     y=(-b-sqrt(D))/( 2 *a);     printf( "discriminant is %f\n" ,D);     if (D== 0 ){         printf( "roots are real and equal: %f, %f" ,x,y);     }     else if (D> 0 ){         printf( "roots are real: %f, %f" ,x,y);     }     else {              printf( "roots are imaginary: %f+%fi , %f-%fi" ,(-b/ 2 *a),sqrt(-D)/( 2 *a),(-b/ 2 *a),sqrt(-D)/( 2 *a));     }     return 0 ; }

2. Basic salary of an employee is input through the keyboard. The DA is 25% of the basic salary while the HRA is 15% of the basic salary. Provident Fund is deducted at the rate of 10% of the gross salary (BS+DA+HRA). Write a program to calculate the Net Salary.

 SOURCE CODE: #include <stdio.h> int main() {   float bs,da,hra,pf,gs,ns;     printf( "enter the basic salary of a employee\n" );     scanf( "%f" ,&bs);     da=( 25.0 / 100 )*bs;     hra=( 15.0 / 100 )*bs;     gs=bs+da+hra;     pf=( 10.0 / 100 )*gs;     ns=gs-pf;     printf( "net salary of employee is %f" ,ns);     return 0 ; }

1. Write a program to calculate the area of triangle using formula A=(s(s-a)(s-b)(s-c))^1/2

SOURCE CODE: #include <stdio.h> #include <math.h> int main() {   float a,b,c,s,A;     printf( "enter the sides of triangle\n" );     scanf( "%f %f %f" ,&a,&b,&c);     s=(a+b+c)/ 2.0 ;     A=sqrt(s*(s-a)*(s-b)*(s-c));     printf( "Area of the triangle is %f" ,A);     return 0 ; }