Pages

Tuesday, January 14, 2014

[H]. (i) If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.

void main()
{
 int f, l, num, sum;
 clrscr();
 printf("Enter Four Digit Number : ");
 scanf("%d",&num);
 l=num%10;
 num=num/10;
 f=num%10;
 num=num/10;
 f=num%10;
 num=num/10;
 f=num%10;
 sum=f+l;
 printf("Sum Of First & Last Digit = %d",sum);
 getch();
}

[h]. (h) If a five-digit number is input through the keyboard, write a program to reverse the number.

void main()
{
 int a, b, c, d;
 unsigned long e, num, rev;
 clrscr();
 printf("Enter Five Digit Number : ");
 scanf("%ld",&num);
 e=num%10;
 num=num/10;
 d=num%10;
 num=num/10;
 c=num%10;
 num=num/10;
 b=num%10;
 num=num/10;
 a=num%10;
 b=b*10;
 c=c*100;
 d=d*1000;
 e=e*10000;
 rev=a+b+c+d+e;
 printf("Reverse = %ld",rev);
 getch();
}

[H]. (g) If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.

void main()
{
 int a, b, c, d, e, sum;
 long num;
 clrscr();
 printf("Enter Five Digit Number : ");
 scanf("%ld",&num);
 e=num%10;
 num=num/10;
 d=num%10;
 num=num/10;
 c=num%10;
 num=num/10;
 b=num%10;
 num=num/10;
 a=num%10;
 sum=a+b+c+d+e;
 printf("Sum=%d",sum);
 getch();
}

[H]. (f) Two numbers are input through the keyboard into twolocations C and D. Write a program to interchange the contents of C and D.

void main()
{
 int a, c, d;
 clrscr();
 printf("Enter Value in C : ");
 scanf("%d",&c);
 printf("Enter Value in D : ");
 scanf("%d",&d);
 a=c;
 c=d;
 d=a;
 printf("C = %d ",c);
 printf("\nD = %d",d);
 getch();
}

[H]. (e) The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.

void main()
{
 float l, b, r, ar, pr, ac, cc ;
 printf("Enter Length Of Rectangle : ");
 scanf("%f",&l);
 printf("Enter Breadth Of Rectangle : ");
 scanf("%f",&b);
 printf("Enter Radius Of Circle : ");
 scanf("%f",&r);
 ar=l*b;
 pr=2*(l+b);
 ac=22*r*r/7;
 cc=2*22*r/7;
 printf("Area Of Rectangle = %f",ar);
 printf("\nPerimeter Of Rectangle = %f",pr);
 printf("\nArea Of Circle = %f",ac);
 printf("\nCircumference Of Circle = %f",cc);
 getch();
}

[H]. (d) Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature the keyboard. Write a program to convert this temperature into Centigrade degrees.

void main()
{
 float f, c;
 clrscr();
 printf("Enter Temperature in Fahrenheit : ");
 scanf("%f",&f);
 c=(f-32)*5/9;
 printf("\n%f Fahrenheit = %f Centigrade",f,c);
 getch();
}