Wednesday, October 19, 2011

Wednesday 10.19.11

#include
int main(void)
{
char ch;

while ((ch = getchar()) != '#')
putchar(ch);

return 0;
}


#include
int main(void)
{
int ch;

while ((ch = getchar()) != EOF)
putchar(ch);

return 0;
}


#include
int main(void)
{
int guess = 1;

printf("Pick an integer from 1 to 100. I will try to guess ");
printf("it.\nRespond with a y if my guess is right and with");
printf("\nan n if it is wrong.\n");
printf("Uh...is your number %d?\n", guess);
while (getchar() != 'y')
{
printf("Well, then, is it %d?\n", ++guess);
while (getchar() != '\n')
continue; //skip rest of input line
}
printf("I knew I could do it!\n");

return 0;
}


#include
void display(char cr, int lines, int width);
int main(void)
{
int ch;
int rows, cols;
printf("enter a character and two integers:\n");
while ((ch = getchar()) != '\n')
{
scanf("%d %d", &rows, &cols);
display(ch, rows, cols);
printf("Enter another character and two integers;\n");
printf("Enter a newline to quit.\n");
}
printf("Bye.\n");

return 0;
}

void display(char cr, int lines, int width)
{
int row, col;

for (row = 1; row <= lines; row++)
{
for (col = 1; col <= width; col++)
{
putchar(cr);
}
putchar('\n');s
}
}


#include
void display(char cr, int lines, int width);
int main(void)
{
int ch; //character to be printed
int rows, cols; //number of rows and columns

printf("Enter a character and two integers:\n");
while ((ch = getchar()) != '\n')
{
if (scanf("%d %d", &rows, &cols) != 2)
break;
display(ch, rows, cols);
while (getchar() != '\n')
continue;
printf("Enter another character and two integers;\n");
printf("Enter a newline to quit.\n");
}
printf("Bye.\n");

return 0;
}

void display(char cr, int lines, int width)
{
int row, col;

for (row = 1; row <= lines; row++)
{
for (col = 1; col <= width; col++)
{
putchar(cr);
}
putchar('\n'); //end line and start a new one
}
}

No comments: