First Step in C Programming: Exploring A.P & G.P Calculations
Excited to share that I've just scratched the basics of C programming! ?? I’ve successfully written my first code using only IF statements and FOR loops to calculate Arithmetic Progression (A.P) and Geometric Progression (G.P) based on user inputs. It’s just the beginning, and I’m eager to dive deeper into the world of programming! #CProgramming #Learning #CodingJourney #TechSkills"
#include <stdio.h>
int main()
{
int a,d,r,t,p,n,i,sum;
printf("1. Arithematic progression\n2. Geometric Progression\nEnter the Number of desired Progression: ");
scanf("%d", &p);
if(p==1)
{
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Enter the first term: ");
scanf("%d", &a);
printf("Enter the common difference: ");
scanf("%d", &d);
sum = 0;
for (i=1;i<=n;i++)
{
t = a + ((i-1)*d);
sum = sum + t;
printf("t_%d = %d\n", i,t);
}
printf("The sum of all the terms is %d", sum);
}
else
{
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Enter the first term: ");
scanf("%d", &a);
printf("Enter the constant ratio: ");
scanf("%d", &r);
sum = 0;
for (i=1;i<=n;i++)
{
t = a;
sum = sum + t;
printf("t_%d = %d\n", i,t);
a = t * r;
}
printf("The sum of all the terms is %d", sum);
}
return 0;
}