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();
}