/*
compiler- Turbo c++ author- Mangilal Sharma
--------------------------------------------------------*/
/* A program to determine ASCII value for a input key. */
#include <stdio.h>
#include <conio.h>
#include <bios.h>
int getkey(void);
void main()
{
int x;
clrscr();
printf("Enter any Key: ");
x=getkey();
printf("\nASCII VALUE OF ENTERED KEY IS: %d",x);
getch();
}
int getkey(void)
{
int key, lo, hi;
key = bioskey(0);
lo = key & 0X00FF;
hi = (key & 0XFF00) >> 8;
return((lo == 0) ? hi + 256 : lo);
}
/*=========================30Nov.,2011=============================*/
This is a try to put the solutions of each possible problem related to C and C++. You can find here C basic lab, C++ basic Lab, Data Structure Lab, DAA Lab, Operating System Lab, Graphics Lab, Compiler Lab, Network Lab, and other problems.
Sunday, 23 December 2012
Count number of characters, blanks, tabs, lines, numerals of a file
/*
compiler- Turbo c++ author- Mangilal Sharma
--------------------------------------------------------*/
/* C++ program to determine number of characters, blanks, tabs, lines, numerals of a file. */
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;
int nol=0,not=0,nos=0,noc=0,non=0;
clrscr();
fp=fopen("data.txt","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch==' ')
nos++;
if(ch=='\n')
nol++;
if(ch=='\t')
not++;
if(ch>=48 && ch<=57)
non++;
}
fclose(fp);
printf("\n Number of characters = %d",noc);
printf("\n Number of blanks = %d",nos);
printf("\n Number of tabs = %d",not);
printf("\n Number of lines = %d",nol);
printf("\n Number of Numerals = %d",non);
getch();
}
/*=========================24Nov.,2011=============================*/
Text File: data.txt
This program taken from http://world-of-c-programming.blogspot.com/
Check regualrly for new programs.
For testing-
some symbols: *&%$$^@!
some numbers: 23445673
some tab spaces: a b c
Output:
/* C++ program to determine number of characters, blanks, tabs, lines, numerals of a file. */
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;
int nol=0,not=0,nos=0,noc=0,non=0;
clrscr();
fp=fopen("data.txt","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch==' ')
nos++;
if(ch=='\n')
nol++;
if(ch=='\t')
not++;
if(ch>=48 && ch<=57)
non++;
}
fclose(fp);
printf("\n Number of characters = %d",noc);
printf("\n Number of blanks = %d",nos);
printf("\n Number of tabs = %d",not);
printf("\n Number of lines = %d",nol);
printf("\n Number of Numerals = %d",non);
getch();
}
/*=========================24Nov.,2011=============================*/
Text File: data.txt
This program taken from http://world-of-c-programming.blogspot.com/
Check regualrly for new programs.
For testing-
some symbols: *&%$$^@!
some numbers: 23445673
some tab spaces: a b c
Output:
Matrix creation by using only one dimensional array
/*
compiler- Turbo c++ author- Mangilal Sharma
--------------------------------------------------------*/
/* Do work of matrix by using only one dimensional array */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
void main()
{
clrscr();
int m,a[100],n;
cout<<"Enter no. of rows for matrix:";
cin>>n;
cout<<"Enter no. of columns for matrix:";
cin>>m;
cout<<"Enter the elements for matrix:\n";
int k=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<"Enter element for matrix location "<<i<<","<<j<<" :";
cin>>a[k++];
}
}
k=0;
for(i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<"matrix location for"<<i<<","<<j<<" :";
cout<<"is"<<&a[k++];cout<<endl;
}
}
int row;
printf("Which row we show u:");
scanf("%d",&row);
k=(row-1)*m;
{
for(int j=0;j<m;j++)
{
cout<<a[k++];cout<<"\t";
}
cout<<endl;
}
getch();
}
/*=========================19Nov.,2011=============================*/
/* Do work of matrix by using only one dimensional array */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
void main()
{
clrscr();
int m,a[100],n;
cout<<"Enter no. of rows for matrix:";
cin>>n;
cout<<"Enter no. of columns for matrix:";
cin>>m;
cout<<"Enter the elements for matrix:\n";
int k=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<"Enter element for matrix location "<<i<<","<<j<<" :";
cin>>a[k++];
}
}
k=0;
for(i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<"matrix location for"<<i<<","<<j<<" :";
cout<<"is"<<&a[k++];cout<<endl;
}
}
int row;
printf("Which row we show u:");
scanf("%d",&row);
k=(row-1)*m;
{
for(int j=0;j<m;j++)
{
cout<<a[k++];cout<<"\t";
}
cout<<endl;
}
getch();
}
/*=========================19Nov.,2011=============================*/
Subscribe to:
Posts (Atom)