Loop Programs Solutions
Loop Programs Solutions
Loop Programs Solutions
#include<stdio.h>
void main()
{
int i,n;
printf(“enter n value”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
printf(“%d * %d = %d\n”,n,i,n*i);
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf(" *");
printf("\n");
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf(" %d",j);
printf("\n");
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
printf(" %d",i);
printf("\n");
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
printf(" %d",j);
printf("\n");
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
printf(" %d",i);
printf("\n");
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=5;i>=1;i++)
{
for(k=30-i;k>=1;k--)
printf(" ");
for(j=1;j<=i;j++)
printf(" *%d",i);
printf("\n");
}
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=5;i>=1;i++)
{
for(k=30-i;k>=1;k--)
printf(" ");
for(j=1;j<=i;j++)
printf(" %d",i);
printf("\n");
}
}
#include<stdio.h>
void main()
{
int i,j,n,k,;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=30-i;k>=1;k--)
printf(" ");
for(j=1;j<=i;j++)
printf(" %d",i);
printf("\n");
}
for(i=n;i>=1;i--)
{
for(k=30-i;k>=1;k--)
printf(" ");
for(j=1;j<=i;j++)
printf("* %d ",i);
printf("\n");
}
getch();
}
#include<stdio.h>
void main()
{
int i,j,n,k,coeff=1;
clrscr();
printf("enter n value");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(k=30-i;k>=1;k--)
printf(" ");
for(j=0;j<=i;j++)
{
if(j==0||i==0)
coeff=1;
else
coeff=coeff*(i-j+1)/j;
printf(" *%d",coeff);
}
printf("\n");
}
16.
#include<stdio.h>
#include<math.h>
main()
{
int i=0,k=0,n,fact=1,j,x;
float sum=0;
printf("\n Enter the value of n");
scanf("%d",&n);
printf("\n Enter the value of x");
scanf("%d",&x);
do {
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
sum=sum+pow(-1,k)*pow(x,i)/fact;
i=i+2;
k++;
}while(i<=2n);
printf("\n sum=%f",sum);
}