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

Are you working on Windows or Unix? I know that windows has some functions in the Win32 API for setting pixels in the console screen.

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

Here's a sampleprogram that draws a sine with the SetPixel() function (as Clockowl suggested):

#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

That's a C++ program btw, not C.

To make it C:

#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.

Comments
Thanks for the heads up!

That's a C++ program btw, not C.

You're absolutely right! I switch between the forums quite a bit and sometimes lose track of where I am :confused:

To make it C

Thanks for the effort.
Hoot!

This article has been dead for over six months. Start a new discussion instead.