Wednesday, 2 July 2025

C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 2

 Q:(i) Consider a currency system in which there are notes of seven  denominations,

namely, Re. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. If  a sum of Rs. N is entered through the keyboard, write a program to 

compute the smallest number of notes that will combine to give Rs. N.


#include<stdio.h>

int main()

{

    int s=0,a[6]={1,2,5,10,50,100},n;

    int i;

    printf("Enter Total Amount :\n");

    scanf("%d",&n);

    for(i=5;i>=0;i--)

    {

        s=s+n/a[i];

        n=n%a[i];

    }

    printf("Total Notes : %d",s);

    return 0;

}


Download Source Code

C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 2

Q: (h) Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

#include<stdio.h>

int main()

{

    int C, D, t;

    printf("Enter value of C: ");

    scanf("%d", &C);

    printf("Enter value of D: ");

    scanf("%d", &D);

    printf("\nBefore swapping: C = %d, D = %d\n", C, D);

    t = C;

    C = D;

    D = t;

    printf("After swapping:  C = %d, D = %d\n", C, D);

    return 0;

}



Download Source Code

C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 2

 Q:(g) If value of an angle is input through the keyboard, write a program to print all its Trigonometric ratios.

/* C Programming Solved Problems Let us C Yashwant Kanitkar Chapter 2 

Q:(g) If value of an angle is input through the keyboard,

write a program to print all its Trigonometric ratios.

*/

#include<stdio.h>

#include<math.h>

#define PI 3.141592

int main()

{

    double angle_deg, angle_rad,sin_val, cos_val, tan_val, cosec_val, sec_val, cot_val;

    printf("Enter angle in degrees:\n");

    scanf("%lf", &angle_deg);

    angle_rad = angle_deg * (PI / 180.0);

    sin_val = sin(angle_rad);

    cos_val = cos(angle_rad);

    tan_val = tan(angle_rad);

    printf("Trigonometric Ratios for %lf degrees:\n", angle_deg);

    printf("sin(%lf) = %lf\n", angle_deg, sin_val);

    printf("cos(%lf) = %lf\n", angle_deg, cos_val);

    

    if (fabs(cos_val) < 1e-6)

        printf("tan(%lf) = Undefined\n", angle_deg);

    else

        printf("tan(%lf) = %lf\n", angle_deg, tan_val);

        

    if (fabs(sin_val) < 1e-6)

        printf("cosec(%lf) = Undefined\n", angle_deg);

    else

        printf("cosec(%lf) = %lf\n", angle_deg, 1.0 / sin_val);


    if (fabs(cos_val) < 1e-6)

        printf("sec(%lf) = Undefined\n", angle_deg);

    else

        printf("sec(%lf) = %lf\n", angle_deg, 1.0 / cos_val);


    if (fabs(tan_val) < 1e-6)

        printf("cot(%lf) = Undefined\n", angle_deg);

    else

        printf("cot(%lf) = %lf\n", angle_deg, 1.0 / tan_val);


    return 0;

}





Download Source Code