C Practical (STUD - VERSION)
C Practical (STUD - VERSION)
C- Programming Language
(Practical Session)
e.g: x^2 + 2x -8
#include <math.h>
main( )
scanf("%f", &b);
v = sqrt ( (b * b ) - (4 * a * c)) ;
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
main()
{
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