Digital-Systems-Assignments/Assignment 2/main.c

21 lines
484 B
C
Raw Normal View History

2019-09-12 06:55:54 +00:00
/*
*Student: S.K Soekhlal
* Number: 4860632
* Assignment: 1.4
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
double a,r,b=0,sum=0; /*Declaring variables*/
int N;
scanf("%lf%d%lf",&a,&N,&r); /*Storing inputted values in variables*/
for(;N>=0;--N){ /*Starting for loop to calculate sum*/
b = a * (pow(r,N)); /*calculating sum*/
sum += b;
}
printf("%.2f\n", sum); /*Printing sum on the screen*/
return 0;
}