Sunday, December 2, 2012

Display string for desired number of times using C++


#include<iostream.h>
int main()
{
int a;
cout<<"Enter number of times to print string \n";
cin>>a;
for(int i=1;i<=a;i++)
{
cout<<"Well done \n";
}
return 0;
}

Conversion of Temperature from Fahrenheit to Celsius using C++


#include<iostream.h>
#include<conio.h>
int main()
{
float f,c;
cout<<"Enter the temparature in farhenheit";
cin>>f;
c=(f-32)*5/9.0;
cout<<"\n Temparature in centigrade is:"<<c;
return 0;
}

Conversion of Temperature from Fahrenheit to Celsius using classes in C++


#include<iostream.h>
#include<conio.h>
class temp
{
public:
float gett()
{
float f;
cout<<"Enter the temparature in farhenheit";
cin>>f;
return f;
}
float calc(float)
{
float c,f;
c=(f-32)*5/9.0;
return c;
}
void display(float)
{
int c;
cout<<"\n Temparature in centigrade is:"<<c;
}
};
int main()
{
float c,f;
temp t;
t.gett();
t.calc(f);
t.display(c);
return 0;
}

Wednesday, November 28, 2012

Read & Write MODE R+ MODE usage in FILES using C language


#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
FILE *f;
char c;
clrscr();
f=fopen("balaram.txt","r+");
if(f==NULL)
{
 printf("File can not appending");
 exit(1);
}
printf("\n contents read");
while(!feof(f))
{
printf("%c",getc(f));
}
printf("write data and to stop press'.':");
while(c!='.')
{
c=getche();
 fputc(c,f);
}
}

FINDING OF TRACE OF A MATRIX


#include<stdio.h>
main()
{
int a[10][10],i,j,sum=0;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(i==j)
sum=sum+a[i][j];
printf("trace of a matrix=%d",sum);
}

Appending & Reading with A+ MODE using C language


#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
FILE *f;
char c=' ';
clrscr();
f=fopen("balaram.txt","a+");
if(f==NULL)
{
printf("\n can not open file");
exit(1);
}
printf("\n write data and to stop process press'#':");
while(c!='#')
{
c=getche();
fputc(c,f);
}
printf("\n contents read");
rewind(f);
while(!feof(f))
printf("%c",getc(f));
}

Writing & Reading of FILE using W+ MODE in C language

#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
FILE *f;
char c=' ';
clrscr();
f=fopen("kemp.txt","w+");
if(f==NULL)
{
printf("\n can not open file");
exit(1);
}
printf("write data and to stop process press '*':");
while(c!='*')
{
c=getche();
fputc(c,f);
}
rewind(f);
printf("\n contents read:");
while(!feof(f))
printf("%c",getc(f));
}

Tuesday, November 27, 2012

Appending DATA to a Pre-Existing FILE using C languge


#include<stdio.h>

#include<conio.h>

#include<process.h>

void main()

{

FILE *f;

char c;

clrscr();

printf("\n contents of file before appending");

f=fopen("balaram.txt","r");

while(!feof(f))

{
 
c=fgetc(f);

 printf("%c",c);

}

f=fopen("balaram.txt","a");

if(f==NULL)

{

 printf("File can not appending");

  exit(1);

}

printf("\n Enter string to append:");

while(c!='.')

{
 
c=getche();

  fputc(c,f);

}

fclose(f);

printf("\n contents of file after appending:\n");

f=fopen("balaram.txt","r");

while(!feof(f))

{

  c=fgetc(f);

  printf("%c",c);

}

}

Writing and reading Data from text FILE using C language


#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
FILE *f,*f1;
char c;
clrscr();
f=fopen("balaram.txt","w");
if (f==NULL)
{
printf("Cannot open file");
exit(1);
}
printf("write data and to stop press '.':");
while(c!='.')
{
c=getche();
fputc(c,f);
}
fclose(f);
printf("\n contents read:");
f1=fopen("balaram.txt","r");
while(!feof(f1))
printf("%c",getc(f1));
}

Biggest Number in Array


/*Biggest Number in array:*/
#include<stdio.h>
 main()
{
  int a[50],size,i,big;

  printf("\nEnter the size of the array: ");
  scanf("%d",&size);
  printf("\nEnter %d elements in to the array: ", size);
  for(i=0;i<size;i++)
      scanf("%d",&a[i]);

  big=a[0];
  for(i=1;i<size;i++){
      if(big<a[i])
           big=a[i];
  }
  printf("Largest element: %d",big);
 return 0;
}

Saturday, October 6, 2012

Message display program in clanguage using putc(),stdout(),stdin() Streams


#include<stdio.h>
main()
{
char ch[]="Programing is fun";
int k=0;
while(ch[k])
putc(ch[k++],stdout);
}

#include<stdio.h>
main(void)
{
char ch[11];
int i;
printf("Input a Text");
for(i=0;i<11;i++)
ch[i]=getc(stdin);
printf("\n The Text inputed was");
for(i=0;i<11;i++)
putc(ch[i],stdout);
}

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...