Wednesday, 29 October 2014

PYRAMID STRUCTER



PYRAMID STRUCTER



1.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=3;i++)
{
for(j=1;j<=i;j++)
{
if((i+j)%2==0)
printf("1 ");
else
printf("0 ");
}
printf("\n");
}
getch();
}


OUTPUT:
1
0 1
1 0 1



2.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k=1;
clrscr();
for(i=1;i<=3;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",k);
k++;
}
printf("\n");
}
getch();
}

OUTPUT:
1
2 3
4 5 6


3.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=4;i>=1;i--)
{
for(j=i;j>=1;j--)
printf("%d ",j);
printf("\n");
}
getch();
}

OUTPUT:
4 3 2 1
3 2 1
2 1
1




4.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf("* ");
printf("\n");
}
getch();
}

OUTPUT:
*
* *
* * *
* * * *
* * * * *


MULTIPLICATION TABLE




MULTIPLICATION TABLE






/*MULTIPLICATION TABLE*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=5;i++)
{
printf("multiplication table of %d\n",i);
for(j=1;j<=10;j++)
{
k=i*j;
printf("%d %d %d",i,j,k);
printf("\n");
}
printf("\n");
}
getch();
}

OUTPUT:
multiplication table of 1
1 1 1
1 2 2
1 3 3
1 4 4
1 5 5
1 6 6
1 7 7
1 8 8
1 9 9
1 10 10

multiplication table of 2
2 1 2
2 2 4
2 3 6
2 4 8
2 5 10
2 6 12
2 7 14
2 8 16
2 9 18
2 10 20

multiplication table of 3
3 1 3
3 2 6
3 3 9
3 4 12
3 5 15
3 6 18
3 7 21
3 8 24
3 9 27
3 10 30

multiplication table of 4
4 1 4
4 2 8
4 3 12
4 4 16
4 5 20
4 6 24
4 7 28
4 8 32
4 9 36
4 10 40

multiplication table of 5
5 1 5
5 2 10
5 3 15
5 4 20
5 5 25
5 6 30
5 7 35
5 8 40
5 9 45
5 10 50


Convert octal number to binary number



Convert octal number to binary number



/*WAP to convert octal to binary*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int oct,dec=0,d,t=0,bin=0,r=1;
clrscr();
printf("enter the octal number:");
scanf("%d",&oct);
while(oct!=0)
{
d=oct%10;
dec=dec+d*pow(8,t);
t++;
oct=oct/10;
}
while(dec!=0)
{
d=dec%2;
bin=bin+(d*r);
r=r*10;
dec=dec/2;
}
printf("the binary number is %d",bin);
getch();
}

OUTPUT:
enter the octal number:12

the binary number is 1010

Sum of digit of a given number


Sum of digit of a given number




/*WAP to find out the sum of digit of a given number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,d,r=0;
clrscr();
printf("enter the number:");
scanf("%d",&n);
while(n>0)
{
d=n%10;
r=r+d;
n=n/10;
}
printf("sum of digit is %d",r);
getch();
}

OUTPUT:
enter the number:123

sum of digit is 6

Convert the binary number to decimal number



 Convert the binary number to decimal number





/*WAP to convert the binary number to  decimal number*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int bin,dec=0,d,t=0;
clrscr();
printf("enter the binary number:");
scanf("%d",&bin);
while(bin!=0)
{
d=bin%10;
dec=dec+d*pow(2,t);
t++;
bin=bin/10;
}
printf("the decimal number is %d",dec);
getch();
}

OUTPUT:
enter the binary number:1111

the decimal number is 15

Convert the decimal number to binary number



Convert the decimal number to binary number




/*WAP to convert the decimal number to binary number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int dec,bin=0,d,t=1;
clrscr();
printf("enter the decimal number:");
scanf("%d",&dec);
while(dec!=0)
{
d=dec%2;
bin=bin+(d*t);
t=t*10;
dec=dec/2;
}
printf("the binary number is %d",bin);
getch();
}

OUTPUT:
enter the decimal number:15

the binary number is 1111

Convert the decimal number to octal number


Convert the decimal number to octal number




/*WAP to convert the decimal number to octal number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int dec,oct=0,d,t=1;
clrscr();
printf("enter the decimal number:");
scanf("%d",&dec);
while(dec!=0)
{
d=dec%8;
oct=oct+(d*t);
t=t*10;
dec=dec/8;
}
printf("the octal number is %d",oct);
getch();
}

OUTPUT:
enter the decimal number:10

the octal number is 12