Thursday, March 27, 2014

Binary to decimal by c#

namespace binary_to_decimal
{
    class Program
    {
        static void Main(string[] args)
        {
            object r;
            long i,n,sum = 0,k=0,u;
            Console.WriteLine("enter the no of degit of the no");
            n = Int64.Parse(Console.ReadLine());
            u = Int64.Parse(Console.ReadLine());
            r = u;
            Console.WriteLine("the no" + r);
               
            long[] b = new long[n];
            Console.WriteLine("enter the no");
            for (i = 0; i < n; i++)
            {
                b[i] = Int64.Parse(Console.ReadLine());
            }
            for (i = n-1; i >=0; i--)
            {
                sum = sum + b[i] * (int)Math.Pow(2, k);
                k++;
            }
            Console.WriteLine("the no is " + sum);

        }
    }
}

complex no in c#

using System.Text;

namespace compalx_no
{
    class complex
    {
        double a, b, c, d;
        public complex(double v, double x)
        {
            a = v;
            b = x;
        }
        public complex mul(complex t, complex r)
        {
            c = t.a * r.a - t.b * r.b;
            d = t.a * r.b + t.b * r.a;
            t.a = c;
            t.b = d;
            return t;


        }
        public complex()
        {
        }
        public void display()
        {
            Console.WriteLine("The result of the complex number" + a + "i" + b);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            complex s = new complex(2, 3);
            complex w = new complex(4, 1);
            complex p = new complex();
            p = s.mul(s, w);
            p.display();
        }
    }
}

Friday, November 2, 2012

palindrome no in c# with out using Length function


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace string_coniration
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = "*";
            string c, b,d=string.Empty,k;
            int i,t;
           
            Console.WriteLine("enter your name");
            c = Console.ReadLine();
            b = c + a;
            for (i = 0; b[i] != '*'; i++)
            {
            }

            t = i;
            Console.WriteLine("the lenth is\t" + i);
            Console.WriteLine("");

 for (i = t-1; i >= 0; i--)
            {
                d = d + b[i];

            }
            Console.WriteLine("" + d);
            k = d + a;
            if (k == b)
            {
                Console.WriteLine("it is a pladrom");
            }
            else
            {
                Console.WriteLine("it is not pladrom");
            }
        }
        }
   
}

Monday, October 22, 2012

pascal tree

Q. write a pascal tree

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
printf("enter the no");
scanf("%d",&n);
for(i=1;i<=n;i++);
{
for(j=1;j<=i;i++)
{
printf("%d",j);
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}

Sunday, October 21, 2012

Fibonacci

Q. write C program for Fibonacci sires.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,k=0,j=1,temp,l;
clrscr();
printf("enter the no");
scanf("%d",&n);
printf("\n%d",k);
printf("%d",j);
for(i=1;i<=n;i++)
{
l=k+j;
printf("%d",l);
temp=k;
k=j;
j=temp+j;
}
getch();
}

leap year

Q. write a c program to find is the given year is Leap year or not.


#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter any year: ");
scanf("%d",&a);

if(((a%4==0)&&(a%100!=0))||(a%400==0))
{
printf("\n%d is a leap year",a);
}
else
{
printf("\n%d is not a leap year",a);
}
getch();
}

Celsius to Fahrenheit

Q. write a c program to change Celsius to Fahrenheit and  Fahrenheit to Celsius .\


#include<stdio.h>
#include<conio.h>
void main()
{
float n,a,b,f,c;
clrscr();
printf("enter 1 for celsius to fahrennheit\n");
printf("enter 2 for fahrennheit to celsius\n");
scanf("%f",&n);
if (n==1)
{
printf("\nenter the celsius \n");
scanf("%f",&a);
f=a* 9/5+32;
printf("%f",f);
printf("\n Thank you");
}
else if(n==2)
{
printf("\nenter the fahrennheit \n");
scanf("%f",b);
c=(b-32)*5/9;
printf("%f",c);
printf("\n Thank you");
}
else
{
printf("\nyou enter the wrong no");
}
getch();
}