Sams Teach Yourself C in 21 Days

(singke) #1
Answers 845

F


printf( “\n\\v\t\tVertical tab” );
printf( “\n\\\\\t\tBackslash” );
printf( “\n\\\?\t\tQuestion mark” );
printf( “\n\\\’\t\tSingle quote” );
printf( “\n\\\”\t\tDouble quote” );
printf( “\n...\t\t...”);
}


  1. The code is as follows:
    / Inputs two floating-point values and /
    / displays their product. /
    #include <stdio.h>


float x, y;
int main( void )
{
puts(“Enter two values: “);
scanf(“%f %f”, &x, &y);
printf(“\nThe product is %f\n”, x * y);
return 0;
}


  1. The following program prompts for 10 integers and displays their sum:
    / Input 10 integers and display their sum. /
    #include <stdio.h>
    int count, temp;
    long total = 0; / Use type long to ensure we don’t /
    / exceed the maximum for type int. /
    int main( void )
    {
    for (count = 1; count <=10; count++)
    {
    printf(“Enter integer # %d: “, count);
    scanf(“%d”, &temp);
    total += temp;
    }
    printf(“\n\nThe total is %d\n”, total);
    return 0;
    }

  2. The code is as follows:
    / Inputs integers and stores them in an array, stopping /
    / when a zero is entered. Finds and displays the array’s /


49 448201x-APP F 8/13/02 11:22 AM Page 845

Free download pdf