EXTRA PYRAMID AND SERIES
EXTRA PYRAMID AND SERIES
pr-1
*****
****
***
**
*
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; j++)
{
printf(" ");
}
for (k = i; k <= rows; k++)
{
printf("*"); // print the Star
}
printf ("\n");
}
getch();
}
pr 2:-
*
**
***
****
*****
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, rows, k;
printf (" Enter a number to define the rows: \n ");
scanf("%d", &rows);
printf("\n");
for (i = 1; i <= rows; i++)
{
for (j = i; j < rows; j++)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
printf("*"); // print the Star
}
printf ("\n");
}
getch();
}
pr3:-
#include<stdio.h>
#include<conio.h>
int main()
{
int n, s, i, j;
printf("Enter number of rows: ");
scanf("%d",&n);
for(i = 1; i <= n; i++)
{
//for loop for displaying space
for(s = i; s < n; s++)
{
printf(" ");
}
//for loop to display star equal to row number
for(j = 1; j <= (2 * i - 1); j++)
{
printf("*");
}
// ending line after each row
printf("\n");
}
}
pr4:-
#include<stdio.h>
#include<conio.h>
int main()
{
int n, s, i, j;
printf("Enter number of rows: ");
scanf("%d",&n);
for(i = 0; i <= n; i++)
{
for(s = n; s > i; s--)
printf(" ");
for(j=0; j<i; j++)
printf("* ");
printf("\n");
}
for(i = 1; i < n; i++)
{
for(s = 0; s < i; s++)
printf(" ");
for(j = n; j > i; j--)
printf("* ");
// ending line after each row
printf("\n");
}
return 0;
}
SERIES PRINTING
PR 1:- Write a program in C to find the sum of the series [ 1-X^2/2!+X^4/4!- .........].
#include <stdio.h>
#include<conio.h>
void main()
{
float x,sum,t,d;
int i,n;
printf("Input the Value of x :");
scanf("%f",&x);
printf("Input the number of terms : ");
scanf("%d",&n);
sum =1; t = 1;
for (i=1;i<n;i++)
{
d = (2*i)*(2*i-1);
t = -t*x*x/d;
sum =sum+ t;
}
printf("\nthe sum = %f\nNumber of terms = %d\nvalue of x = %f\n",sum,n,x);
getch();
}
#include<stdio.h>
#include<conio.h>
int main()
{
int num = 1, count;
float sum = 0.0, fact;
while(num <= 7)
{
fact = 1;
for(count = 1; count <= num; count++)
{
fact = fact * count;
}
return 0;
}