Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1.Write a program to covert decimal into Binary number.

Solution:

#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,n,j,b[100];
printf("Decimal to Binary Conversion\n");
printf("\nEnter the Decimal Number: ");
scanf("%d",&n);
while (n>0)
{
b[i]=n%2;
n=n/2;
i++;
}
printf("Its Binary Equivalent is: ");
j=i-1;
for (i=j;j>=0;j--)
{
printf("%d", b[j]);
}
getch();
}

OUTPUT:

Decimal to Binary Conversion


Enter decimal number: 5
Its Binary equivalent is: 101

********************************************************************************

2.Write a program to find the sum of five consecutive even integers.

Solution:

#include<stdio.h>
#include<conio.h>
void main()
{
int n1, n2, i, sum = 0;
printf("Enter the number ");
scanf("%d",&n1);
if(n1%2==1)
{
n1=n1+1;
}
printf("The Sum of the five consecutive even integers starting from %d: \n",n1);
n2=n1+8;
for (i = n1; i <= n2; i++)
{
if (i % 2 == 0 )
sum = sum + i;
}
printf(" %d ",sum);
getch();
}

OUTPUT:

Enter the number 6


The Sum of the five consecutive even integers starting from 6:
50

You might also like