Tuesday, 14 May 2013

10. To find the perimeter and area of a circle


10. /* To find the perimeter and area of a circle */
/* Area of a circle with radius 'r' is PI*r*r and Perimeter is 2*PI*r */
main()
{
float r,PI;
PI=3.14;
clrscr();
printf("Enter the radius of the circle -> ");
scanf("%f",&r);
printf("\nThe area is %7.2f and perimeter is %7.2f",PI*r*r,2*PI*r);
getch();
}

9. Program to convert temperature Fahrenheit into Celsius


9. /* Program to convert temperature Fahrenheit into Celsius */
/* degree c=5/9*(f-32) */
/* c-Celsius & f-Fahrenheit */
main()
{
float c,f;
clrscr();
printf("Enter the temperature in Fahrenheit ");
scanf("%f",&f);
c=5.0/9.0*(f-32.0);
printf("\nTemperature in Celsius is %f \n",c);
getch();
}

8. printf numbers from 1 to 100 with formatted output


8. /* printf numbers from 1 to 100 with formatted output */
main()
{
int i;
clrscr();
for(i=1;i<=100;i++)
printf("%4d",i);
getch();
}

7. String formatted output


7. /* String formatted output */
main()
{
clrscr();
printf("%4s\n","Computer Screen"); /* output -> 'Computer Screen' */
printf("%.8s\n","Computer Screen"); /* output -> 'Computer' */
printf("%16.8s\n","Computer Screen"); /* output -> 'Computer' */
getch(); /* with 8 leading blanks */
}

6. Format for string input


6. /* Format for string input */
main()
{
char str[7];
clrscr();
printf("Enter a string ");
scanf("%4s",str);
puts(str); /* if the input is 'computer', the output is 'comp' */
getch();
}

5. Find the sum and average of 3 numbers


5. /* Find the sum and average of 3 numbers */
main()
{
float a,b,c,sum,avg;
a=b=c=0;
clrscr();
printf("Enter the value of a -> ");
scanf("%f",&a);
printf("\n\nEnter the value of b -> ");
scanf("%f",&b);
printf("\n\nEnter the value of c -> ");
scanf("%f",&c);
sum=a+b+c;
avg=sum/3;
printf("\n\n Sum is %8.0f",sum);
printf("\n\n Average is %10.2f",avg);
getch();
}