Program with for loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
for(i=0;i<10;i++)
{
printf("%d\n",i );
}
}
Output:
Program with while (pre increment)
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
while (i<10)
{
i++;
printf("%d\n",i );
}
}
Output:
Program with while (pre increment)
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
while (i<10)
{
printf("%d\n",i );
i++;
}
}
Output:
Program with do-while loop ( post increment)
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
do
{
printf("%d\n",i );
i++;
}
while(i<10);
}
Output:
Program with do-while loop ( pre increment)
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
do
{
i++;
printf("%d\n",i );
}
while(i<10);
}
Output:
Program with nested for( printing rectangle triangle with *)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=0;i<=5;++i)
{
for(j=0;j<=i;++j)
{
printf("*");
}
printf("\n");
}
}
Output:
Program with nested for:
11
222
3333
44444
555555
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,c=1;
for(i=1;i<=5;++i)
{
for(j=0;j<=i;++j)
{
printf("%d",c);
}
c=c+1;
printf("\n");
}
}
Output:
Program to Print n prime numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int c,i,j;
for (i=1;i<70;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c=c+1;
}
}
if(c==2)
{
printf("\n %d",i);
}
c=0;
}
}
Output:
Program with nested for:
*
***
*****
*******
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,c;
for ( j = 0; j <=5; j++)
{
c=2*j+1;
for ( i = 5; i >=j; i--)
{
printf(" ");
}
for(k=1;k<=c;k++)
{
printf("*");
}
printf("\n");
}
}
Output:
Program to print structure.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,c;
for ( j = 0; j <=5; j++)
{
c=2*j+1;
for ( i = 5; i >=j; i--)
{
printf(" ");
}
for(k=1;k<=c;k++)
{
printf("*");
}
printf("\n");
}
}
Output:
No comments:
Post a Comment