0% found this document useful (0 votes)
2 views5 pages

C Programming Array Practice Problems

The document contains a series of C programming exercises focused on arrays and mathematical computations using loops. Each problem includes a code snippet, input values, and expected output results for various mathematical functions such as sums, cosines, and sines. The exercises are designed to enhance understanding of arrays and programming logic in C.

Uploaded by

AADHARSH M
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

C Programming Array Practice Problems

The document contains a series of C programming exercises focused on arrays and mathematical computations using loops. Each problem includes a code snippet, input values, and expected output results for various mathematical functions such as sums, cosines, and sines. The exercises are designed to enhance understanding of arrays and programming logic in C.

Uploaded by

AADHARSH M
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

DSA assignment-1

Lab 1 – Arrays and C Programming Practice


Problems
Date: 10-12-2025

1.
Code:
#include <stdio.h>
int main()
{
double x,sum,term,fact; int i,n;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term=1; sum=1; fact=1;
for (i = 1; i <= n; i++)
{ term = term * x;
sum = sum + (i + 1) * term;
}
printf("Sum = %lf", sum);
return 0;
}
Input:
Give x and n 0.3 100

Output:
Sum = 2.040816
2.
Code:
#include <stdio.h>
int main()
{
double x,sum,term; int i,n,sign=-1;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term=1; sum=1;
for (i = 1; i <= n; i++)
{ term = term * x;
sum = sum + sign * term;
sign = -sign;
}
printf("Sum = %lf", sum);
return 0;
}
Input:
Give x and n 0.3 100

Output:
Sum = 0.769231
3.
Code:
#include <stdio.h>
int main()
{
double x,sum,term;int i, n;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term=1; sum=1;
for (i = 1; i < n; i++)
{ term = term * x;
if (i % 4 == 1 || i % 4 == 2)
sum -= term;
else
sum += term;
}
printf("Sum = %lf", sum);
return 0;
}
Input:
Give x and n 0.3 100

Output:
Sum = 0.642202
4.
Code:
#include <stdio.h>
int main()
{
double x,sum,term;int i, n;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term=1; sum=0;
for (i = 1; i <= n; i++)
{
term = term * x;
sum = sum + term / i;
}
printf("Sum = %lf", sum);
return 0;
}
Input:
Give x and n 0.3 100

Output:
Sum = 0.356675
5.
Code:
#include <stdio.h>
int main()
{
double x,sum,term;int i,n,sign=-1;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term=1; sum=1;
for (i = 1; i <= n; i++)
{
term = term * x * x / ((2*i-1)*(2*i));
sum = sum + sign * term;
sign = -sign;
}
printf("cos(x) = %lf", sum);
return 0;
}
Input 1 : Input 2 :
Give x and n 0.3 10 Give x and n 1.05 10
Output 1 : Output 2:
cos(x) = 0.955336 cos(x) = 0.497571
6.
Code:
#include <stdio.h>
int main()
{
double x,sum,term;int i,n,sign=-1;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term = x;sum = x;
for (i = 1; i <= n; i++)
{
term = term * x * x / ((2*i)*(2*i+1));
sum = sum + sign * term;
sign = -sign;
}
printf("sin(x) = %lf", sum);
return 0;
}
Input 1 : Input 2 :
Give x and n 0.3 10 Give x and n 1.05 10
Output 1 : Output 2:
sin(x) = 0.295520 sin(x) = 0.867423

7.
Code:
#include <stdio.h>
int main()
{
double x,sum,term;int i, n;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term = 1;sum = 0;
for (i = 1; i <= n; i++)
{
term = term * x;
sum = sum + (i*(i+1)/2.0) * term;
}
printf("Sum = %lf", sum);
return 0;
}
Input:
Give x and n 0.3 100

Output:
Sum = 0.874636
8.
Code:
#include <stdio.h>
int main()
{
double x,sum,term;int i, n;
printf("Give x and n ");
scanf("%lf %d",&x,&n);
term = 1;sum = 0;
for (i = 1; i <= n; i++)
{
term = term * x;
if (i % 3 != 0)
sum += term;
}
printf("Sum = %lf", sum);
return 0;
}
Input 1 : Input 2 :
Give x and n 2 5 Give x and n 1 10
Output 1 : Output 2:
Sum = 54.000000 Sum = 7.000000

Practice Problems on Arrays

You might also like