C Operators #Tutorial 08

  In this article, we are gonna to discuss questions to expert using C operators




Before doing the tutorial 08, watch this video to get an idea about Precedence & Associativity of Operators .

Here you can find the tutorial 08 questions pdf to practice C operators  ;

https://www.thecn.com/uploads/646a63/646a6321c2ab142a210164a5/s3/NjMzNWEyM2JhOGE1NWUxZjk5NWIzNTcxLzY0NmE2MzFlYTQ2ODBiOTQzZTAxMDk5YS9JQ1QxNDAyX1R1dG9yaWFsXzA4LnBkZg/d98e205dae89b6a10ee38cce99845dcf.pdf

1.Type in and run the all programs presented in lecture note 7 and 8. Briefly describe the theory/ concept you learned from these programs separately.

  • Defining the terms operators, operands, operator precedence, and associativity.
  • Describing operators in C programming language.
  • Practicing the effect of different operators in the C programming language.
  • Justifying evaluation of expressions in programming.
  • Applying taught concepts for writing programs.

2. Write a program to evaluate the polynomial shows here.

3- 5+ 6 for = 2.55

    Answer
#include <stdio.h>
int main() {
    double x = 2.55;
    double result;

    result = 3 * x * x * x - 5 * x * x + 6;

    printf("The result of the polynomial for x = %.2f is: %.2f\n", x, result);

    return 0;
}

3. Write a program that evaluates the following expression and displays the results (remember to use  exponential format to display the result): 

                (3.31 × 10-8 × 2.01 × 10-7) / (7.16 × 10-6 + 2.01 × 10-8) 

Answer

#include <stdio.h>

int main() 

{

    double number1 = 3.31e-8;

    double number2 = 2.01e-7;

    double number3 = 7.16e-6;

    double number4 = 2.01e-8;   

    double result = (number1 * number2) / (number3 + number4);


    printf("Result: %e\n", result);

    return 0;

}

4. To round off an integer i to the next largest even multiple of another integer j, the following formula can be used: 

        Next_multiple = i + j - i % j 

        For example, to round off 256 days to the next largest number of days evenly divisible by a week, values of i = 256 and j = 7 can be substituted into the preceding formula as follows:


 Next_multiple = 256 + 7 - 256 % 7 

                           = 256 + 7 - 4 

                           = 259 

Write a program to find the next largest even multiple for the following values of i and j: (Use keyboard to input values for i and j)

    Answer

#include <stdio.h>

int main(){

int i,j,next_multiple;


printf("Enter the value of an i:");

scanf("%i",&i);


printf("\nEnter the value of an j:");

scanf("%i",&j);  


next_multiple=i+j-(i%j);


printf("\nNext largest even multiple=%i",next_multiple);

return 0;

}

5.Write a program to input the radius of a sphere and to calculate the volume of the sphere. 

                        Volume =  4/3*pi*radius3

     Answer

#include <stdio.h>

int main()

{

float r,v;

const PI=3.14;


printf("Enter the radius of the sphere:");

scanf("%f",&r);


v = (4/3)*PI* r*r*r;

printf("Volume of the sphere:%f",v);


return 0;

}

6. 100 spherical ice (cubes) of a given radius are placed in a box of a given width, length and height. Calculate the height of the water level when the ice melts. Neglect the change in volume when ice converts to water.

    Answer
#include <stdio.h>

int main() {
    double radius, width, length, height, ice_volume, box_volume, water_height;
    int num_ice_cubes;

    printf("Enter the radius of the ice cubes: ");
    scanf("%lf", &radius);

    printf("Enter the width, length, and height of the box: ");
    scanf("%lf %lf %lf", &width, &length, &height);

    printf("Enter the number of ice cubes: ");
    scanf("%d", &num_ice_cubes);

    ice_volume = (4.0/3.0) * 3.14 * radius * radius * radius;

    ice_volume *= num_ice_cubes;

    box_volume = width * length * height;

    water_height = (box_volume - ice_volume) / (width * length);

    printf("Height of the water level when ice melts: %.2f\n", water_height);

    return 0;
}

7. Write a program to input your mid term marks of a subject marked out of 30 and the final exam marks out of 100. Calculate and print the final results. 

Final Result = Mid Term + 70% of Final Mark

    Answer

#include <stdio.h>

int main() {

    int midTermMarks, finalExamMarks;

    double finalResult;


    printf("Enter mid-term marks [out of 30]: ");

    scanf("%d", &midTermMarks);


    printf("Enter final exam marks [out of 100]: ");

    scanf("%d", &finalExamMarks);


    finalResult = midTermMarks + 0.7 * finalExamMarks;


    printf("Final Result: %.2f\n", finalResult);

    return 0;

}

  • 8. Input the source file and destination file name as command line arguments and print the following message to standard output:
    “Copy the details in <file name 1> to <file name 2> at 23.59.59”
    Answer
#include <stdio.h> int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: %s <source_file> <destination_file>\n", argv[0]); return 1; } char *source_file = argv[1]; char *destination_file = argv[2]; printf("Copy the details in %s to %s at 23.59.59\n", source_file, destination_file); return 0; }

9. Input the target rate as command line argument and compute the total commission as follows:
Total commission = ( total sale × 0.2 × target rate ) + cash flow.
Cash flow is a constant.

    Answer
#include <stdio.h>
#include <stdlib.h>

#define CASH_FLOW 1000 // Define the constant cash flow

int main(int argc, char *argv[]) {
    if (argc != 2) {
        printf("Usage: %s <target_rate>\n", argv[0]);
        return 1;
    }

    float target_rate = atof(argv[1]);

    if (target_rate <= 0) {
        printf("Error: Target rate must be a positive number.\n");
        return 1;
    }

    float total_sale = 5000;

    float total_commission = (total_sale * 0.2 * target_rate) + CASH_FLOW;

    printf("Total commission: %.2f\n", total_commission);

    return 0;
}

BMS Group Members :

·    01)M.G. Janeesha Sinty

Registration number-ICT/21/22/043

CN- JG1539


·    02)R.D. Malsha Nethmini Premathilaka

Registration number- ICT/21/22/085

CN- MN1032


·    03)S. Basuru Rupasinghe

Registration number- ICT/21/22/132

CN- SR1777

Previous Post Next Post

Contact Form