Programming Fundamentals:Looping 1 (Session 4)

Program 1

#include<stdio.h>
int main()
{
int n,i,m;
scanf("%d", &n);
i=1;
while(n>=i)
{
m=i*i;
    i++;
    printf("%d ",m);
}
return 0;
}
Program 2

#include<stdio.h>

int main()

{

int n,i,m;

int a[100];

scanf("%d", &n);

a[0]=n-1;

m=a[0];

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

{

a[i]=m+(n-i);

m=a[i];

}

for(i=(n-1);i>=0;i--)

printf("%d ",a[i]);

return 0;

}


Program 3

#include<stdio.h>

int main()

{

int n,i,c,j=3;

scanf("%d",&n);

if(n>=1)

{

printf("2 ");

}

for(i=2;i<=n;)

{

for(c=2;c<=j-1;c++)

{

if(j%c==0)

break;

}

if (c==j)

{

printf("%d ",j);

i++;

}

j++;

}

return 0;

}


Program 4

#include<stdio.h>

int main()

{

int n,i,t=6;

scanf("%d",&n);

for(i=0;i<=n-1;i++)

{

t=t+5*i;

printf("%d ",t);

}

return 0;

}


Program 5

#include<stdio.h>

#include<math.h>

int main()

{

int n,i,t;

scanf("%d",&n);

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

{

t=pow(3,i);

printf("%d ",t);

}

return 0;

}

Program 6

#include<stdio.h>

int main()

{

int n,i,j;

scanf("%d", &n);

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

{

for(j=1;j<=(n-i+1);j++)

printf("%d ",j);

printf("\n");

}

return 0;

}


Program 7

#include<stdio.h>

int main()

{

int i,j,n,k;

scanf("%d",&n);

k=n;

for(i=n;i>=1;i--)

{

for(j=k-i+1;j<=n;j++)

{

printf("%d ",j);

}

printf("\n");

}

return 0;

}

Program 8


#include<stdio.h>

int main()

{

int n,i,j;

scanf("%d",&n);

for(i=n;i>=1;i--)

{

for(j=i;j>=1;j--)

{

printf("%d ",j);

}

printf("\n");

}

return 0;

}


Program 9

#include<stdio.h>

int main()

{

int i,j,n,m;

scanf("%d",&n);

m=n;

for(i=n;i>=1;i--)

{

for(j=n;j>=m-i+1;j--)

{

printf("%d ",j);

}

printf("\n");

}


return 0;

}

Program 10

#include<stdio.h>

int main()

{

int i,j,n;

scanf("%d",&n);

//m=n;

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

{

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

{

printf("%d ",j);

}

printf("\n");

}


return 0;

}

Program 11

#include<stdio.h>

int main()

{

int i,j,m,n;

scanf("%d",&n);

m=n;

for(i=1;i<=n;i++,m--)

{

for(j=m;j<=n;j++)

printf("%d ",j);

printf("\n");

}


return 0;

}


Program 12

#include<stdio.h>

int main()

{

int i,j,n;

scanf("%d",&n);

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

{

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

{

printf("%d ",i);

}

printf("\n");

}


return 0;

}


Program 13

#include<stdio.h>

int main()

{

int i,j,m,n;

scanf("%d",&m);

n=m;

for(i=m;i>=1;i--)

{

for(j=n-i+1;j>=1;j--)

{

printf("%d ",i);

}

printf("\n");

}

return 0;

}


Program 14

#include<stdio.h>

int main()

{

int m,i,j;

scanf("%d",&m);

for(i=m;i>=1;i--)

{

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

{

printf("%d ",i);

}

printf("\n");

}

return 0;

}


Program 15

#include<stdio.h>
int main()
{
int m,i,j,n;
scanf("%d",&m);
n=m;
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("%d ",i);
}
n--;
printf("\n");
}
return 0;
}

SHARE
    Blogger Comment
    Facebook Comment

1 comments :

loading...