Posts: 468
Threads: 89
Joined: Oct 2011
Assignment [Total Marks 20]
Q No. 1
Write the C Program that should print the 25 rows of DOS screen with different colors, i.e. your DOS screen should be displayed in such a way that every two consecutive rows should have different colors. Following is the sample output of your program.
[FONT="]
[/FONT]
Attached Files
Fall 2011_CS609_1.doc (Size: 69.5 KB / Downloads: 139)
Posts: 9,583
Threads: 8,089
Joined: Apr 2011
Code:
#include <stdio.h>
#include <windows.h>
char ColorsArray[] = {BACKGROUND_RED,BACKGROUND_GREEN,BACKGROUND_BLUE };
int main ( void )
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
SetConsoleTextAttribute ( h, ColorsArray[0] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] |
BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[1]| ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[0] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] | BACKGROUND_INTENSITY );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[2] );
printf ( " " );
SetConsoleTextAttribute ( h, ColorsArray[1] | ColorsArray[0] );
printf ( " " );
SetConsoleTextAttribute ( h, wOldColorAttrs);
system("pause");
return 0;
}
Posts: 5
Threads: 0
Joined: Apr 2011
it is not true.......................pls help sir.........?
Posts: 4
Threads: 0
Joined: Oct 2011
How to compile this code?
Posts: 3
Threads: 0
Joined: Feb 2011
Plz tell how to compile n in which format it is needed to upload
Posts: 468
Threads: 89
Joined: Oct 2011
oh you don't know about the compilation
Posts: 4
Threads: 0
Joined: Oct 2011
Posts: 4
Threads: 0
Joined: Oct 2011
This code is not correct.