Tutorial 3


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.


2. Write a program to evaluate the polynomial shown here:

3x 3 - 5x 2 + 6 for x = 2.55

     #include <stdio.h>

           #include<math.h>

            int main ()

           {

                double x=2.55;

                double result;

                 result= 3*pow(x,3)- 5* pow(x,2)+6;

                 printf ("The result of the polyominal for x= 2.55 is: %1f\n", 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)

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

    #include <stdio.h>

           #include<math.h>

            int main ()

           {

                double x=2.55;

                double result;

                result= 3*pow(x,3)- 5* pow(x,2)+6;

                 printf ("The result of the polyominal for x= 2.55 is: %1f\n", result);

                 return 0;

              }


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)





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

Volume = 4/3*pi*radius3

                #include<stdio.h>

                #define PI 3.1415

                int main ()

                {

                   float volume, radius;

                   printf("Enter the radius : ");

                   scanf("%f", &radius);

                   volume = ( 1.33 * PI * radius * radius * radius);

                    printf("Volume : %f \n", volume);

                     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.

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

                   #include<stdio.h>

                    int main()

                    

                          float final_result, mid_term_marks, final_exam_marks;

                          printf("enter your mid_term_marks(out of 30):");

                          scanf("%f", &mid_term_marks);

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

                          scanf("%f", &final_exam_marks);

                          final_result = mid_term_marks + 0.7*final_exam_marks;

                          printf("Your final result is:%.2f\n",final_result);

                          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”

 #include<stdio.h>

                    int main (int argc, char*argv[])

                    {

                        printf("Copy the details in %s to %s  at 23.59.59",argv[0],argv[1]);

                        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. 

0 comments:

Post a Comment