C Prog.

C-programming is the base of computer programming.
C is a easy to learn procedural language.


C Graphics :
How to draw a Circle:
How to draw a Line: More>>



/*Accept a number and check whether it is perfect or not*/
/*A number that is equal to sum of its factors. eg: 6 is perfect 1+2+3=6*/


#include<stdio.h>
#include<conio.h>
void main()
{
 int no,i,sum=0;
  clrscr();
  printf("Enter a no:-");
  scanf("%d",&amp;no);
 for(i=1;i<no;i++)
  {
   if(no%i==0)
    sum=sum+i;
  }
if(sum==no)
printf("%d is a perfect no",no);
else
printf("Not a perfect no");
getch();
}




String Handling in C-programming:


 #include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[80];
int i=0,j,vcnt=0;
clrscr();
printf("Enter a string\n");
gets(a);
while(a[i]!='\0')
{
  if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')
  { vcnt++;
  }
 i++;
}
printf("\nvowel count=%d",vcnt);


getch();
}


#include<stdio.h>
#include<conio.h>
void main()
{
int r,c;
clrscr();
for(r=1;r<=5;r++)
{
if(r==1||r==5)
 for(c=1;c<=5;c++)
  printf("*");
 else
 printf("*   *");
 printf("\n");
}
getch();
}





#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,sp;
clrscr();
for(r=1;r<=9;r++)
{
for(sp=9;sp>r;sp--)
printf(" ");
for(c=r;c>=1;c--)
printf("%d",c);
for(c=2;c<=r;c++)
printf("%d",c);
printf("\n");
}
getch();
}






#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,i;
clrscr();
for(r=90;r>=65;r--)
{
  for(c=65;c<=r;c++)
  printf("%c",c);
  for(i=r-1;i>=65;i--)
  printf("%c",i);


  printf("\n");
}
getch();
}



#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,sp;
clrscr();
for(r=9;r>=1;r--)
{

    for(sp=9;sp>r;sp--)
    printf(" ");
   for(c=r;c>=1;c--)
   printf("%d",c);

       for(c=2;c<=r;c++)
       printf("%d",c);
  printf("\n");
  }
  getch();
  }




#include<stdio.h>
#include<conio.h>


void main()
{
int r,c;
char ch;
clrscr();
for(r=1;r<=26;r++)
{
ch='A' ;
for(c=1;c<=r;c++,ch++)


 printf("%c",c%2==0?ch+32:ch);


 printf("\n");
}


getch();
}






#include<stdio.h>
#include<conio.h>
void main()
{
int r,c,i;
clrscr();
for(r=9;r>=1;r--)
{
for(c=1;c<=r;c++)
printf("%d",c);
for(i=r-1;i>=1;i--)
printf("%d",i);
printf("\n");
}
getch();
}



C Graphics :



How to draw a Circle ?


#include<graphics.h>
 void main()
{
  int gm,gd=0;
  initgraph(&gd,&gm,"G:\\tc\\bgi");
/*used to start the graphics system 3rd parameter is location of Graphics Library*/
  circle(300,300,100); // built in function parameters are x, y and radius
  getch();
 }



How to draw a Line ?

#include<graphics.h>
 void main()
{

  int gm,gd=0;
  initgraph(&gd,&gm,"G:\\tc\\bgi");
  line(100,100,300,100); // built in function parameters are x1, y1 and x2,y2
  getch();
 }


How to draw a Arc ?

#include<graphics.h>
 void main()
{

  int gm,gd=0;
  initgraph(&gd,&gm,"G:\\tc\\bgi");
  setcolor(12);//set light red color as current
  arc(200,200,90,270,100); //parameters are x,y, start angle, end angle and radius of arc.
  getch();
 }


How to draw a Rectangle ?

#include<graphics.h>
 void main()
{

  int gm,gd=0;
  initgraph(&gd,&gm,"G:\\tc\\bgi");
  setcolor(2);    //set green color
outtextxy(200,200,"Welcome to Graphics"); //parameters are x,y and Message.
  getch();
 }


User Interaction in C ?




#include<graphics.h>
 void main()
{
  int gm,gd=0;
  initgraph(&gd,&gm,"G:\\tc\\bgi");
  setcolor(2);            //set green color
  bar(150,150,400,300);
  outtextxy(200,200,"Welcome to Graphics"); //parameters are x,y and Message.
  getch();
 }
Have a Question ? Need Help in College Assignments, Need Code that is not available here? Just leave a comment & get your code instantly.

Tips to Enhance Your Blog