Added previous assignments

This commit is contained in:
Shaquille K. Soekhlal
2019-09-12 08:55:54 +02:00
parent fc59dd3913
commit 395564a57a
7 changed files with 175 additions and 0 deletions

21
Assignment 2/main.c Normal file
View File

@ -0,0 +1,21 @@
/*
*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;
}