| | |
Complete C Program to draw a sin curve without any application
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
•
•
i need a complete C program to draw a sin curve without any application and the output should be displayed in dos prompt. can anyone please help me
cpp Syntax (Toggle Plain Text)
#include<windows.h> #include<iostream> #include <cmath> int main() { HWND console = GetConsoleWindow(); HDC dc = GetDC(console); int pixel =0; COLORREF C1= RGB(255,0,0); //red for (double i = 0; i< 6.3; i+=0.05) { SetPixel(dc,pixel,(int)(100+50*sin(i)),C1); pixel+=1; } ReleaseDC(console, dc); std::cin.ignore(); return 0; }
I remember something about a polyline() function that can connect the dots, but that's for you to research.
Personally I would really recommend to use wxWidgets (or something like it). It has great function for drawing graphs and is platform-independent
Last edited by niek_e; Jun 17th, 2008 at 11:11 am.
That's a C++ program btw, not C.
To make it C:
And link it with gdi32.
To make it C:
C Syntax (Toggle Plain Text)
#define _WIN32_WINNT 0x0500 #include <windows.h> #include <stdio.h> #include <math.h> int main() { HWND console = GetConsoleWindow(); HDC dc = GetDC(console); int pixel = 0; unsigned int loopcounter = 0; unsigned int loopmax = 126; COLORREF C1= RGB(255,0,0); //red double i = 0; for (loopcounter = 0; loopcounter < loopmax; loopcounter++) { SetPixel(dc,pixel,(int)(100+50*sin(i)),C1); pixel++; i += 0.05; } ReleaseDC(console, dc); getchar(); return 0; }
And link it with gdi32.
![]() |
Other Threads in the C Forum
- Previous Thread: fread() doesn't work when 're-used' in a for( ; ;) function
- Next Thread: Length of file
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm command copyanyfile creafecopyofanytypeoffileinc createprocess() database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework ide include initialization input interest intmain() iso kernel keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue oddnumber odf openwebfoundation overwrite pause pdf pointer posix power process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






