Showing posts with label Simple. Show all posts
Showing posts with label Simple. Show all posts

C Program To Find Simple Interest

How to write a C Program to find Simple Interest Using function with Parameters and Returning a Value in C Programming Language ?

Solution For C Program :

/*C Program To Find Simple Interest*/

#include <stdio.h>
void main()
{
int p, t;
float r;
float SimpleInterest(int p, int t, float r);
printf("\nEnter the Principle Amount, Term, Rate of Interest : ");
scanf("%d%d%f", &p, &t, &r);
printf("\nThe Simple Interest for the Principle Amount %d for %d Years with an
Interest of %0.2f", p, t, r);
printf("\n is %f.", SimpleInterest(p, t, r));
}
float SimpleInterest(int p, int t, float r)
{
return((p * t * r) / 100);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program Calculation of Simple Interest

How to write a C Program Calculation of Simple Interest in C Programming Language ?


Solution:
This Program calculates the value of Simple Interest. The Values of Principle, Rate of Interest and the number of years is input through the keyboard.

  1. Write a program to calculate the simple interest.
  2. The values of principle, rate of interest and the number of years are input from the keyboard.
  3. Display the value of the calculated Simple interest on a new line.
  1. //C Program to calculate simple interest by given principle, rate of interest and time.
  2. #include<stdio.h>
  3. main ()
  4.  
  5. {
  6. int p, n;
  7. float r, si;
  8. printf(" Enter the values of p, n, r: ");
  9.  
  10. scanf("%d %d %f", &p, &n, &r);
  11.  
  12. si=p*n*r/100;
  13.  
  14. printf("%f", si);
  15. }

C Program to simple iteration method

How to Write a C Program to simple iteration method in C Programming Language ?


Solution:


#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
double *xk, *xk1;
double t, l1, l2, max, Axk = 0, eps;
int n, i, j, k, count = 0;;
int compare()
{
 max = abs(xk[0] - xk1[0]);
 for (i = 1; i < n; i++)
 {
  if (abs(xk[i] - xk1[i]) > max)
   max = abs(xk[i] - xk1[i]);
 }
 if (max <= eps) return 1;
 else return 0;
}
int main()
{
 FILE *f1;
 FILE *f2;
 double **a;
 f1 = fopen("input.txt", "r");
 fscanf(f1, "%d", &n);    //считываем размер матрицы коэффициентов
 a = (double**)malloc(n*sizeof(double*));     //выделяем память под матрицу
 for (i = 0; i < n; i++)
  a[i] = (double*)malloc((n + 1)*sizeof(double));
 for (i = 0; i < n; i++)   //заполняем матрицу коэффициентов
  for (j = 0; j <= n; j++)
   fscanf(f1, "%lf", &a[i][j]);
 fscanf(f1, "%lf%lf", &l1, &l2);
 fscanf(f1, "%lf", &eps);
 xk = (double*)malloc(n*sizeof(double));
 xk1 = (double*)malloc(n*sizeof(double));
 for (i = 0; i < n; i++)
 {
  xk[i] = 1;
  xk1[i] = 0;
 }
 t = 2 / (l1 + l2);
 do
 {
  for (i = 0; i < n; i++)
  {
   for (j = 0; j < n; j++)
   {
    Axk += a[i][j] * xk[j];
   }
   xk1[i] = xk[i] - t*(Axk - a[i][n]);
   Axk = 0;
  }
  for (k = 0; k < n; k++)
  {
   xk[k] = xk1[k];
  }
  count++;
 } while (compare() == 0);
 fclose(f1);
 f2 = fopen("output.txt", "w");
 for (i = 0; i < n; i++)
  fprintf(f2, "x[%d] = %.8f\n", i + 1, xk1[i]);
 fprintf(f2, "число итераций = %d", count);
 


 fclose(f2);
 return 0;
}