Apply Now :

Members

Sikkim Manipal University

Rank No. 1

Showing posts with label C Programs. Show all posts
Showing posts with label C Programs. Show all posts

Sum of Two No. Example in C

Monday, 12 December 2011

/* C Program Sum of Two No. Example
Calibre IT & Management Institute
[ Krishna Suman ]
*/

#include<stdio.h>
main()
{
int A, B, Sum ;
clrscr();
printf("\n Enter First No. : ");
scanf("%d",&A);
printf("\n Enter Second No. : ");
scanf("%d",&B);
Sum = A + B ;
printf("\n Sum of two No. : %d",Sum);
getch();

}





File Handeling in C Language

/* C Program => File Handeling
Calibre IT & Management Institute
[ Krishna suman ]
*/


#include<stdio.h>

void main()
{
FILE *file1;
char c;
int choice;
char op;
clrscr();
do
{
printf("\t\tMenu\n\t1. Enter The Information\n\t2. Display The Information\n");
printf("\n \t Enter Your Choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("\n\t\t\t Information \n");
file1=fopen("Krishna.doc","w");


while((c=getchar())!=EOF)
{

putc(c,file1);
}
fclose(file1);
break;

case 2:
printf("\n\t\t\t Information\n");
printf("\nResult :");
file1=fopen("Krishna.doc","r");
while((c=getc(file1))!=EOF)
printf("%c",c);
fclose(file1);
break;

default:
exit(1);
}
printf("Enter Y To Continue:");
flushall();
scanf("%c",&op);
}while(op=='y' || op=='Y');
getch();
}






Structure in C

/* C Program => Structure in C
Calibre IT & Management Institute
[ Krishna Suman ]
*/

#include <stdio.h>
#include <conio.h>
int main()
{
struct dob
{
int day;
int month;
int year;
};
struct student
{
struct dob d;
int rollno;
char name[25];
int totalmark;
}stud[25];
int n,i;
clrscr();
printf("Enter total number of students\n\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter details of %d-th student\n\n",i+1);
printf("\nName : ");
scanf("%s",&stud[i].name);
printf("\nRoll number : ");
scanf("%d",&stud[i].rollno);
printf("\nTotal mark : ");
scanf("%d",&stud[i].totalmark);
printf("\nDate of birth (Format:01 06 2010) : ");
scanf("%d%d%d",&stud[i].d.day,&stud[i].d.month,&stud[i].d.year);
}
clrscr();
printf("\n\n\tSTUDENTS DETAILS:\n");
for(i=0;i<n;i++)
{
printf("\n\nRoll number\t\t:\t%d",stud[i].rollno);
printf("\nName\t\t\t:\t%s",stud[i].name);
printf("\nTotel mark\t\t:\t%d",stud[i].totalmark);
printf("\nDate of birth\t\t:\t%d / %d / %d \n\n",stud[i].d.day,stud[i].d.month,stud[i].d.year);
}
getch();
return 0;
}






Font Style in C (Graphics)

/* C Program Graphics in C
Font Style in C
Calibre It & Management Institute
[ Krishna suman ]*/

#include<graphics.h>
#include<conio.h>

main()
{
int gd = DETECT, gm, x = 25, y = 25, font = 0;
initgraph(&gd,&gm,"C:\\TC\\BIN");

for ( font = 0 ; font <= 10 ; font++)
{
settextstyle(font, HORIZ_DIR, 1);
outtextxy(x, y, "Text with different fonts");
y = y + 25;
}

getch();
closegraph();
return 0;
}




Graphics in C (Shape Drawing)

/* C Program (Graphics in C)
Calibre IT & Management Institute
[ Krishna Suman ]
*/


#include<graphics.h>
#include<conio.h>

void main()
{
int gd=DETECT, gm;
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };
initgraph(&gd, &gm, "");
outtextxy(180,10,"Calibre IT & Management Institute");
circle(100,100,50);
outtextxy(75,170, "Circle");
rectangle(200,50,350,150);
outtextxy(240, 170, "Rectangle");
ellipse(500, 100,0,360, 100,50);
outtextxy(480, 170, "Ellipse");
line(100,250,540,250);
outtextxy(300,260,"Line");

sector(150, 400, 30, 300, 100,50);
outtextxy(120, 460, "Sector");
drawpoly(6, poly);
outtextxy(340, 460, "Polygon");
getch();
closegraph();
}






Nested For Loop Example 3


/* C Program [ Krishna Suman] */
#include<stdio.h>
main()
{
int i, j,a=9 ,k;
clrscr();
for(i=1; i<=9; i++)
{ printf("\t\t");

a=a-1;
for(j=a; j>=1; j--)
{
printf(" ");
}
for(k=1; k<=i; k++)
{
printf("0");
printf(" ");
}
printf("\n");
}
for(i=8; i>=1; i--)
{
printf("\t\t");
a= a+1;
for(j=1; j<=a; j++)
{
printf(" ");
}
for(k=i; k>=1; k--)
{
printf("0");
printf(" ");

}
printf("\n");
}

getch();
}








Nested For Loop Example 2


/*C Program [ Krishna ]*/
#include<stdio.h>
main()
{
int i, j,a=9 ,k;
clrscr();
for(i=8; i>=1; i--)
{
printf("\t\t");
a= a+1;
for(j=1; j<=a; j++)
{
printf(" ");
}
for(k=i; k>=1; k--)
{
printf("0");
printf(" ");

}
printf("\n");
}



for(i=1; i<=9; i++)
{ printf("\t\t");

a=a-1;
for(j=a; j>=1; j--)
{
printf(" ");
}
for(k=1; k<=i; k++)
{
printf("0");
printf(" ");
}
printf("\n");
}

getch();
}

Nested For Loop Example

/* C Program [Krishna Suman]*/
#include<stdio.h>
main()
{
int i, j,a=9 ,k;
clrscr();
for(i=8; i>=1; i--)
{
printf("\t\t");
a= a+1;
for(j=1; j<=a; j++)
{
printf(" ");
}
for(k=i; k>=1; k--)
{
printf("0");
printf(" ");

}
printf("\n");
}


for(i=1; i<=9; i++)
{ printf("\t\t");

a=a-1;
for(j=a; j>=1; j--)
{
printf(" ");
}
for(k=1; k<=i; k++)
{
printf("0");
printf(" ");
}
printf("\n");
}
for(i=8; i>=1; i--)
{
printf("\t\t");
a= a+1;
for(j=1; j<=a; j++)
{
printf(" ");
}
for(k=i; k>=1; k--)
{
printf("0");
printf(" ");

}
printf("\n");
}


for(i=1; i<=9; i++)
{ printf("\t\t");

a=a-1;
for(j=a; j>=1; j--)
{
printf(" ");
}
for(k=1; k<=i; k++)
{
printf("0");
printf(" ");
}
printf("\n");
}

getch();
}








Piramid Usinf For Loop

/*
C Program : Piramid
Calibre IT & Management Institute
[ Krishna Suman ]
*/

#include<stdio.h>
main()
{
int i, j,a=9 ,k;
clrscr();
for(i=1; i<=9; i++)
{ printf("\t\t");

a=a-1;
for(j=a; j>=1; j--)
{
printf(" ");
}
for(k=1; k<=i; k++)
{
printf("0");
printf(" ");
}
printf("\n");
}

getch();
}

=====================  OUTPUT  ==================================



Print Star Using For Loop

/*
C Program : Piramid
Calibre IT & Management Institute
[ Krishna Suman ]
 */

#include<stdio.h>
main()
{
int i, j,a=0 ,k;
clrscr();
for(i=8; i>=1; i--)
{
a= a+1;
for(j=1; j<=a; j++)
{
printf(" ");
}
for(k=i; k>=1; k--)
{
printf("%d",k);
printf(" ");

}
printf("\n");
}

getch();
}







=====================  Out Put  =================================

SMU

SMU
Sikkim Manipal University