0% found this document useful (0 votes)
28 views6 pages

Name:-Tapajyoti Ghosh Roll NO:-: GCECTB-R19-2037 Sub:-Programming Assignment On - Three Loops

The document contains 5 programming assignments involving loops in C language. Each assignment includes the C code with comments identifying key lines of code. The code is followed by the output of the program when run. Assignment 1 contains nested for loops to print a pyramid pattern. Assignment 2 uses for loops and print statements to output a number pattern. Assignment 3 uses for loops, if-else, and increment/decrement to print a binary number pattern. Assignment 4 contains while, for, and nested loops to calculate an approximation of e^x. Assignment 5 uses a for loop, variable assignments, and increment/decrement to calculate the value of e^x in one line of code.

Uploaded by

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

Name:-Tapajyoti Ghosh Roll NO:-: GCECTB-R19-2037 Sub:-Programming Assignment On - Three Loops

The document contains 5 programming assignments involving loops in C language. Each assignment includes the C code with comments identifying key lines of code. The code is followed by the output of the program when run. Assignment 1 contains nested for loops to print a pyramid pattern. Assignment 2 uses for loops and print statements to output a number pattern. Assignment 3 uses for loops, if-else, and increment/decrement to print a binary number pattern. Assignment 4 contains while, for, and nested loops to calculate an approximation of e^x. Assignment 5 uses a for loop, variable assignments, and increment/decrement to calculate the value of e^x in one line of code.

Uploaded by

abc d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name:-Tapajyoti Ghosh

Roll NO:- GCECTB-R19-2037


Sub:- Programming Assignment
on_Three Loops
4 1 1

1.

#include <stdio.h>

int main(void)

int i,j=5,k,x;

for(i=1;i<=5;i++)

for(k=1;k<j;k++) //Line 1

printf(" ");

for(x=1;x<=i;x++) //Line
////Line
// Line2 22
{

printf("%d ",i);

printf("\n");

j--;

return 0;

OUTPUT:
4 2 2

2.

#include <stdio.h>

int main(void)

int i,j;

for(i=1;i<=5;i++)

for(j=2;j<=2*i;printf("%d ",j),j+=2); //Line 1

for(j=(2*i)-2;j>=2;printf("%d ",j),j-=2); //Line 2

printf("\n");

return 0;

OUTPUT:
4 3 3

3.

#include<stdio.h>

int main(void)

int i,j,k;

k=i+j; //Line 1

for(i=1;i<=5;i++) //Line 2

for(j=1;j<=i;j++) //Line 3

if(k%2==1) //Line 4

printf("1 ");

else

printf("0 ");

k++; //Line 5

printf("\n");

return 0;

OUTPUT:
4 4 4

4.

#include <stdio.h>

#define pi 3.14159 //Line 1

int main()

int i=1,j,n,t,f,flag=- 1; //Line 2

float x, p, sum = 0;

printf("Enter number of terms:");

scanf("%d", &n);

printf("Enter theta:");

scanf("%d", &t);

x=t*pi/180; //Line 3

while(i<=n)

p =1;

f=1;

j=1;

while(j<= i)

p = p * x; //Line 4

f= f*j;

j++;

flag= - 1 * flag;

sum+= flag*p/f;
OUTPUT:
i+=2; //Line 5

printf("sum=%f",sum);

return 0;

}
4 5 5

5.

#include <stdio.h>

int main(void)

int i=1,n=20;

float x,sum=1,t=1; //Line 1

printf("Enter x:");

scanf("%f",&x);

for(i=1;i<=n;t=t*x/i,sum=sum+t,i++); //Line 2

printf("e^%f=%f",x,sum);

return 0;

OUTPUT:

You might also like