0% found this document useful (0 votes)
18 views14 pages

C Practical (STUD - VERSION)

Uploaded by

jfixcoding
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views14 pages

C Practical (STUD - VERSION)

Uploaded by

jfixcoding
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

CSC 202

C- Programming Language
(Practical Session)

Prepared by : Akande Noah O.


Tackling Computable Problems

1. Identify the inputs


 What are the appropriate data types

 What variables will be used to store the inputs

2. Determine the operations and operators to


be performed on the input variables
 Addition, Subtraction, Multiplication, Division etc.
 In what order will the operations be carried out?

3. Determine how to present the results


 What variables will be used to store the results.
Example 1
Write a C program to accept a temperature
value in Fahrenheit and convert same value to
Celsius.

Note : Celcius = (Fahrenheit value - Freezing


Point) * Scale factor
Where: Freezing Point = 32 and Scale factor = ( 5/9
)
Tackling Computable Problems

1. Identify the inputs


 What are the appropriate data types

 What variables will be used to store the inputs

2. Determine the operations and operators to


be performed on the input variables
 Addition, Subtraction, Multiplication, Division etc.
 In what order will the operations be carried out?

3. Determine how to present the results


 What variables will be used to store the results.
#include <stdio.h>
#include <math.h>
main()
{
# define Freez_pt 32
#define Scale_factor (5.0/9.0)
float cel, fah ;
printf( "P1ease enter your temperature in fahrenheit "
);
scanf( "%f", &fah);
// cel= ((fah-32) *(5.0/9.0)) ;
cel= ((fah-Freez_pt) *Scale_factor ) ;
printf ( "\n Your temperature in Celsius is : %.3f \n",
Example 2
A C program to compute the roots of a
quadratic equation ax2 + bx + c = 0. your roots
must be in 3 decimal places.

e.g: x^2 + 2x -8

Roots are -4 and +2


Rule:

1. Identify the inputs


 What are the appropriate data types

 What variables will be used to store the inputs

2. Determine the operations and operators to


be performed on the input variables
 Addition, Subtraction, Multiplication, Division etc.
 In what order will the operations be carried out?

3. Determine how to present the results


 What variables will be used to store the results.
#include <stdio.h>

#include <math.h>

main( )

float v, a, b, c, root1, root2 ;

printf( "P1ease enter the first number " );

scanf( "%f", &a);

printf("P1ease enter the second number ");

scanf("%f", &b);

printf("P1ease enter the third number ");

scanf ( "%f", &c);

v = sqrt ( (b * b ) - (4 * a * c)) ;

root1 = (-b + v ) / (2 * a);

root2 = (-b - v ) / (2 * a);

printf ( "\n\n first root : %.3f \n\n", root1);

printf ( "\n\n second root : %.3f \n\n", root2);

return 0 ;
Example 3
Write a C program that requests and adds two
fractions together.

Such that:
#include <stdio.h>
#include <math.h>
main()
{
int num1, denum1, num2, denum2, num_result,
denum_result;
printf( "P1ease enter the first fraction " );
scanf( "%d %d", &num1, &denum1);
printf( "P1ease enter the second fraction " );
scanf( "%d %d", &num2, &denum2);
num_result= num1 * denum2 + num2 *
denum1;
denum_result= denum1 * denum2;
printf ( "\n Your result is %d / %d ", num_result,
denum_result);
return 0 ;
Example 4
Only one of the expression ++a and a++ is

equivalent to a+=1. Which is it ? Justify your


answer.
Write a C program that requests for the

tuition fee of a student and adds 10% late


registration fee to it. Display the final amount
respective students are expected to pay.
(your final answer should be in two decimal
places).
 #include <stdio.h>

 main()
{

 float fee, new_fee;

 printf( "P1ease enter your tuition fee " );


 scanf( "%f", &fee);

 new_fee = fee + (0.1* fee);

 printf ( "\n Your new fee is N %.2f", new_fee);

 return 0 ;

 }
Tutor Marked Assignment 1
A common problem in personal finance is that of
determining how much money will accumulate in a bank
account after n years if a known amount, P, is deposited
initially and the account collects interest at a rate of r
percent per year which compounds annually. The formula
below can be used to implement this:
A^n = pow((A), n );
F= P (1 + i)n
Where: F represents the future accumulation of money
(including the original sum, P, which is known as the
principal) and i is the decimal representation of the
interest; i.e., i = r/100 (for example, an interest rate of r
= 7% would correspond to i = 0.07).
Write a C program to determine the future accumulation
of cash deposited. Your results should be in 2 decimal
Tutor Marked Assignment 2
Write a C program that formats product information

entered by the user. A section with the program


should like this:
Enter item number: 583

Enter unit number: 13.5

Enter purchase date (mm/dd/yyyy) : 10/24/2010

Item Unit Purchase


583 $13.50 10/24/2010
The item number and date should be left justified; the

unit price should be right justified. Hint: use tabs to

You might also like