#include
#include
void main()
{
int i,j,k,s,n;
printf(" ENTER THE NO OF ROWS");
scanf("%d",&n);
for(i=1,s=n;i<=n;i++,s--)
{
for(k=1;k<=s;k++)
printf(" ");
for(j=1;j<=i;j++)
printf("*");
printf(" ");
}
getch();
}
Program to create pyramid of Star in C
Program to create double pyramid in C
#include
#include
void main(void)
{
clrscr();
int i,j,k,l,b,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf(" ");
for(l=0;l<=i;l++)
printf(" ");
for(j=i+1;j<=n;j++)
printf("%d",j);
for(k=n-1;k>i;k--)
printf("%d",k);
}
b=n-1;
for(i=0;i<=n-1;i++)
{
printf(" ");
for(l=n-2;l>=i;l--)
printf(" ");
for(j=b;j<=n;j++)
printf("%d",j);
for(k=n-1;k>=b;k--)
printf("%d",k);
b--;
}
getch();
}
Program to show Palindrome Verification in C, string is Palindrome or Not.
int palindrome( char* string )
{
int i = 0, j = strlen( string ) - 1;
while( i < j / 2 )
{
if( string[ i++ ] == string[ j-- ] )
;
else
{
printf( "The String is not Palindrome" );
return -1;
}
}
printf( "The string is Palindrome" );
return 0;
}
int main( )
{
palindrome( "Info " );
palindrome( "Computers" );
return 0;
}
Program Showing Binary Equivalent of an Integer in C
main()
{
int n;
char ch;
while(1)
{
clrscr();
printf("Enter an integer to see its Binary Equivalent");
printf("Enter ");
scanf("%d",&n);
showbits(n);
printf("continue ?");
ch=getch();
if(ch==27)
break;
}
}/*End of main()*/
showbits(int n)
{
int i,bit,mask,count=0;
printf(" ");
for(i=15;i>=0;i--)
{
mask=1<
bit=n & mask;
if(bit==mask)
printf("1");
else
printf("0");
count++;
if(count%4==0)
printf(" ");
}
}/*End of showbits()*/
CPU scheduling (Round Robin) Program in C
#include
#include
main()
{
int st[10],bt[10],wt[10],tat[10],n,tq;
int i,count=0,swt=0,stat=0,temp,sq=0;
float awt=0.0,atat=0.0;
clrscr();
printf("Enter number of processes:");
scanf("%d",&n);
printf("Enter burst time for sequences:");
for(i=0;i<=n;i++)
{
scanf("%d",&bt[i]);
st[i]=bt[i];
}
printf("Enter time quantum:");
scanf("%d",&tq);
while(1)
{
for(i=0,count=0;i<=n;i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]=>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
for(i=0;i<=n;i++)
{
wt[i]=tat[i]-bt[i];
swt=swt+wt[i];
stat=stat+tat[i];
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("Process_no Burst time Wait time Turn around time
");
for(i=0;i<=n;i++)
printf("%d %d %d %d
",i+1,bt[i],wt[i],tat[i]);
printf("Avg wait time is %f
Avg turn around time is %f",awt,atat);
getch();
}
Program to create Pyramid of Numbers in C
#include
#include
int pyramid( int length )
{
int line = 1;
int j = 1, i, k = length;
while( length-- )
{
if( j == 1 ) {
for( i = 1; i <= length + 5; i++ )
printf( " " );
printf( "%d", j++ );
k--;
line++;
}
else if( i % 2 ){
for( i = 1; i <= length + 5; i++ )
printf( " " );
for( i = 1; i <= line; i++ )
printf( "%d ", ( j++ % 10 ) );
printf( " " );
line++;
k--;
}
else {
for( i = 1; i <= length + 5 ; i++ )
printf( " " );
for( i = 1; i <= line; i++ )
printf( "%d ", ( j++ % 10 ) );
printf( " " );
line++;
k--;
}
}
return 0;
}
int main( )
{
int length;
printf( "Enter the list length " );
scanf( "%d", &length );
pyramid( length );
getch( );
return 0;
}
Program to create Analog and Digital clock in C
# include
# include
# include
# include
# include
# define pi 3.141592654
int x;
float x30,x60,y30,y60;
void paint1()
{
setcolor(GREEN);
outtextxy(297,60," ");
outtextxy(297,332," ");
outtextxy(435,198," ");
outtextxy(160,198," ");
setcolor(RED);
outtextxy(375,85,"è");
outtextxy(420,260,"è");
outtextxy(170,135,"è");
outtextxy(220,310,"è");
setcolor(LIGHTBLUE);
outtextxy(420,135,"ì");
outtextxy(375,310,"ì");
outtextxy(220,83,"ì");
outtextxy(175,260,"ì");
}
void paint2()
{
setcolor(RED);
outtextxy(297,60,"è");
outtextxy(297,332,"è");
outtextxy(435,198,"è");
outtextxy(160,198,"è");
setcolor(LIGHTBLUE);
outtextxy(375,85,"ì");
outtextxy(420,260,"ì");
outtextxy(170,135,"ì");
outtextxy(220,310,"ì");
setcolor(GREEN);
outtextxy(420,135," ");
outtextxy(375,310," ");
outtextxy(220,83," ");
outtextxy(175,260," ");
}
void paint3()
{
setcolor(LIGHTBLUE);
outtextxy(297,60,"ì");
outtextxy(297,332,"ì");
outtextxy(435,198,"ì");
outtextxy(160,198,"ì");
setcolor(GREEN);
outtextxy(375,85," ");
outtextxy(420,260," ");
outtextxy(170,135," ");
outtextxy(220,310," ");
setcolor(RED);
outtextxy(420,135,"è");
outtextxy(375,310,"è");
outtextxy(220,83,"è");
outtextxy(175,260,"è");
}
void graph()
{
cleardevice();
setcolor((++x)%15+1);
if(x%2)
outtextxy(180,10,"THERE IS NO GOD EXCEPT ALLAH");
else
outtextxy(130,20,"PRAISE ALLAH THE MOST BENEFICIENT AND MERCIFUL");
setcolor(GREEN);
circle (300,200,150);
circle(300,200,2);
setcolor(14);
circle (300,200,100);
setcolor(3);
circle (300,200,120);
setcolor(RED);
circle(300,50,2);
circle(450,200,2);
circle(150,200,2);
circle(300,350,2);
setcolor(BLUE);
circle(300+x30,200+y30,2);//1
circle(300-x30,200+y30,2);//11
circle(300+x30,200-y30,2);//5
circle(300-x30,200-y30,2);//7
circle(300+x60,200+y60,2);//2
circle(300+x60,200-y60,2);//4
circle(300-x60,200-y60,2);//8
circle(300-x60,200+y60,2);//10
if(x%2)
{
setcolor(x);
outtextxy(300+x30*1.1,200+y30*1.1,"1");//1
outtextxy(300-x30*1.1,200+y30*1.1,"11");//11
outtextxy(300+x30*1.1,200-y30*1.1,"5");//5
outtextxy(300-x30*1.1,200-y30*1.1,"7");//7
outtextxy(300+x60*1.1,200+y60*1.1,"2");//2
outtextxy(300+x60*1.1,200-y60*1.1,"4");//4
outtextxy(300-x60*1.1,200-y60*1.1,"8");//8
outtextxy(300-x60*1.15,200+y60*1.1,"10");//10
outtextxy(460,200,"3");
outtextxy(300,360,"6");
outtextxy(140,200,"9");
outtextxy(290,40,"12");
}
}
void plot(int h , int m , int s)
{
char a[2],b[2],c[2];
setcolor( LIGHTCYAN );
itoa(h,a,10);
outtextxy(450,100,a);
outtextxy(470,100,":");
itoa(m,a,10);
outtextxy(490,100,a);
outtextxy(510,100,":");
itoa(s,a,10);
outtextxy(530,100,a);
setcolor( LIGHTGREEN );
if( h<13 )
outtextxy( 290 , 250 , "AM");
else
outtextxy( 290 , 250, "PM");
h=h%12;
setlinestyle(SOLID_LINE , 1 , 3);
setcolor( RED );
line(300,200,300+floor(100*cos(((h*5+m/10.0)*6-90)*pi/180)),
200+floor(100*sin(((h*5+m/10.0)*6-90)*pi/180)));
setcolor(BLUE);
setlinestyle(SOLID_LINE,1,3);
line(300,200,300+floor(120*cos((m*6-90)*pi/180)),
200+floor(120*sin((m*6-90)*pi/180)));
setcolor(MAGENTA);
setlinestyle(SOLID_LINE,1,1);
line(300,200,300+floor(120*cos((s*6-90)*pi/180)),
200+floor(120*sin((s*6-90)*pi/180)));
}
void timexy()
{
int h,m,s;
struct time t;
while(1)
{
//clrscr();
cleardevice();
graph();
gettime(&t);
//printf("
The current time is:
%2d:%02d:%02d.%02d
",
// t.ti_hour, t.ti_min, t.ti_sec,t.ti_hund);
h=t.ti_hour;
m=t.ti_min;
s=t.ti_sec;
if(s%3==0)
paint1();
else if(s%3==1)
paint3();
else paint2();
plot(h,m,s);
delay(995);
}
}
main()
{
int i=DETECT,m;
char a[100],b[10]="jalpari";
x30=floor(150*cos((30-90)*pi/180));
y30=floor(150*sin((30-90)*pi/180));
x60=floor(150*cos((60-90)*pi/180));
y60=floor(150*sin((60-90)*pi/180));
initgraph(&i,&m,"d:\tc\bgi");
i=0;
printf("
PASSWORD==>");
do
{
a[i]=getch();
if(!(a[i]==(char)13))
{
printf("vasim");
i++;
}
else {a[i]='
Program to Count Blanks Spaces ,Tabs and Newlines in Given String In C
#include
int main(void)
{
int nb,nt,nl,c;
nb=nt=nl=0;
while((c=getchar())!=EOF)
{
if(c==' ')
++nb;
if(c==' ')
++nt;
if(c==' ')
++nl;
}
printf("No. of Blanks is %d,No. of Tabs is %d and No. of Newlines is %d",nb,nt,nl);
return 0;
}
Write a program to find permutation in c
#include
#include
int lev=-1,n,val[50],a[50];
void main()
{
int i,j;
clrscr();
printf("Enter how many numbers");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
val[i]=0;
j=i+1;
scanf("%d",&a[j]);
}
visit(0);
getch();
}
visit(int k)
{
int i;
val[k]=++lev;
if(lev==n)
{
for(i=0;i<=n;i++)
printf("%2d",a[val[i]]);
printf(" ");
}
for(i=0;i<=n;i++)
if(val[i]==0)
visit(i);
lev--;
val[k]=0;
}
Program To Calculate SQRT square root Of Any Number.
Program To Calculate SQRT square root Of Any Number.
#include
#include
#include
//prototyping of used functions
void decide(void);
void counter(void);
void evenodd(void);
void checkdigits(void);
void mainfun(void);
void mainfun2(void);
void printresult(void);
int next2digits(void);
int dig_after_dot(void);
//global variables
int
realflag=0,oddflag=0,digitflag=0,dotflag=0,DC=1,AC=0,FC,t,i,c,c2,r;
long int l,j,rem,k,M;
char N[18],ans[14],ch;
float fn;
//**************************************************************
void main()
{
clrscr();
fflush(stdin);
printf("
Enter the no : ");
gets(N);
//when -ve no is entered then exit program
if(N[0]=='-'||
Program to multiply two 3*3 matrices.
#include
#include
/*Program to multiply two 3*3 matrices*/
void main()
{
int a[3][3],b[3][3],c[3][3],i,j,k;
clrscr();
printf("Enter elements of A:");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&a[i][j]);
printf("Enter elements of B:");
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
scanf("%d",&b[i][j]);
printf("A:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%d ",a[i][j]);
printf(" "); //To change line.
}
printf("B:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%d ",b[i][j]);
printf(" ");
}
k=0;
while(k<=2)
{
for(i=0;i<=2;i++)
{
int sum=0;
for(j=0;j<=2;j++)
sum=sum+a[i][j]*b[j][k];
c[i][k]=sum;
}
k++;
}
printf(" Result: ");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%d ",c[i][j]);
printf(" ");
}
getch();
}
Program to show Taylor's series-e^x in C
#include
#include
#include
long int factorial(int n);
void main()
{
int x,i;
float s,r;
char c;
clrscr();
printf("You have this series:-1+x/1! + x^2/2! + x^3/3! + x^4/4!..x^x/x!");
printf("To which term you want its sum of ? ");
scanf("%d",&x);
s=0;
for (i=1;i<=x;i++)
{ s=s+((float)pow(x,i)/(float)factorial(i));
}
printf("The sum of %d terms is %f",x,1+s);
fflush(stdin);
getch();
}
long int factorial(int n)
{
if (n<=1)
return(1);
else
n=n*factorial(n-1);
return(n);
}
Solution of Transportation Cost Problem in C
#include
#include
main()
{
int flag=0,flag1=0;
int s[10],d[10],sn,eop=1,dm,a[10][10];
int i,j,sum=0,min,x[10][10],k,fa,fb;
clrscr();
/* Getting The Input For the Problem*/
printf("Enter the number of Supply");
scanf("%d",&sn);
printf("Enter the number of Demand");
scanf("%d",&dm);
printf("Enter the Supply Values");
for(i=0;i<=sn;i++) enter="" the="" demand="" j="0;j<=sn;j++)" elements="" of="" i="0;i=d[j]) //Check the supply greater than equal to
demand
{
x[i][j]=a[i][j]*d[j]; // Calculate amount * demand
s[i]=s[i]-d[j]; // Calculate supply - demand
j++; // Increment j for the deletion of the row
or
column
}
}
/* The Cost Matrix is Estimated here */
printf("Given Cost Matrix is :
");
for(fa=0;fa<=sn;fa++) fb="0;fb<=dm;fb++)" the="" allocated="" cost="" matrix="" is="" fa="0;fa<=sn;fa++)" sum="sum+x[fa][fb];" transportation="" estimated="" and="" d="" pre="">
SAMPLE INPUT
11
13
17
14
16
18
14
10
21
24
13
10
11
11
11
11
Given Cost Matrix is :
11 13 17 14
16 18 14 10
21 24 13 10
11 11 11 11
Allocated Cost Matrix is
2200 650 0 0
0 3150 700 0
0 0 2925 500
0 0 0 2200
The Transportation cost:12325
*/
Program to find the reminder without using reminder in C
Program to find the reminder without using reminder in C.
#include
#include
main()
{
int a,b;
clrscr();
printf("enter the value of a=");
scanf("%d",&a);
printf("enter the value of b=");
scanf("%d",&b);
while(a-b>=b)
{
a=a-b;
}
printf("the reminder is =%d",a-b);
getch();
}
Program to generate cos series in C
# include
# include
main()
{
int i,p,n;
clrscr();
printf("enter the number in term of series");
scanf("%d",&n);
printf("xcos(x)=1");
for(i=1;i<=n;i++)
{
p=2*i;
if(i%2==0)
printf("+");
else
printf("-");
printf(x^%d/%d!",p,p);
getch();
}
}