C and CPP Programming
C and CPP Programming.
Tuesday, January 1, 2013
Thursday, March 3, 2011
Mai wapas aa gaya hu. Kal se naye post karna start karunga
Tuesday, November 2, 2010
Haapy Deepavali
Happy Deepavali By :-
SATYAM SRIVASTAVA / DIKSHA SRIVASTAVA
SHUBHAM SRIVASTAVA
PRIYAM SRIVASTAVA
Saturday, October 30, 2010
18.Program to demonstrate reversing of an input text using a function with string arguments.
// Program to demonstrate reversing of an input text
// using a function with string arguments.
#include <stdio.h>
#include <iostream.h>
#include<conio.h>
/* strlen - return length of string s
*/
int strlen(char s[])
{
int i;
for (i = 0; s[i] != '\0'; ++i);
return (i);
}
/* reverse - reverses order of characters in a string
*/
void reverse(char s[])
{
char t;
short i, j;
for (i = 0, j = strlen(s) - 1; i < j; ++i, --j)
t = s[i], s[i] = s[j], s[j] = t;
}
main()
{
char line[BUFSIZ]; /* the line of input text */
cout<<endl;
cout<<"Input String to obtain in reverse");
cin.getline(line,BUFSIZ);
reverse(line);
cout<<endl;
cout<<line;
getch();
}
// using a function with string arguments.
#include <stdio.h>
#include <iostream.h>
#include<conio.h>
/* strlen - return length of string s
*/
int strlen(char s[])
{
int i;
for (i = 0; s[i] != '\0'; ++i);
return (i);
}
/* reverse - reverses order of characters in a string
*/
void reverse(char s[])
{
char t;
short i, j;
for (i = 0, j = strlen(s) - 1; i < j; ++i, --j)
t = s[i], s[i] = s[j], s[j] = t;
}
main()
{
char line[BUFSIZ]; /* the line of input text */
cout<<endl;
cout<<"Input String to obtain in reverse");
cin.getline(line,BUFSIZ);
reverse(line);
cout<<endl;
cout<<line;
getch();
}
Friday, October 22, 2010
17.Matrices : To implement cell value of a defined matrix
// Program for : Matrices : To implement cell value of a defined matrix
// Input: Row & Col. and Output : Cell element of the points Row, Col.
#include <stdlib.h>
#include <iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x, y; // Loop Counter
int x1, y1, repeat;
// x, y Think like that if you input x = 1, y = 3
// You will output "69", that how a matrix works
int matrix[4][4] = { 12, 4, 23, 6,
45, 78, 3, 57,
69, 23, 9, 2,
34, 11, 5, 99 };
cout<<"My Matrix: "<< endl << endl;
for( x = 0; x < 4; x++)
{
for( y = 0; y < 4; y++)
{
cout<< matrix[x][y] << " ";
}
cout<<endl;
}
cout<< endl <<"Both x and y have a max point of 3" << endl;
do
{
cout<< endl <<"Enter in x and y points[ x <space> y ]: ";
cin>> x1 >> y1;
cout<<"Point ("<< x1 <<", " << y1 <<") = " << matrix[x1][y1] << endl
<< endl;
cout<<"Would You like Output new points (0 to quit)? ";
cin>> repeat;
}while( repeat != 0);
cout<<endl;
cout<<"Press any key to continue";
getch();
return 0;
}
// Input: Row & Col. and Output : Cell element of the points Row, Col.
#include <stdlib.h>
#include <iostream.h>
#include<conio.h>
int main()
{
clrscr();
int x, y; // Loop Counter
int x1, y1, repeat;
// x, y Think like that if you input x = 1, y = 3
// You will output "69", that how a matrix works
int matrix[4][4] = { 12, 4, 23, 6,
45, 78, 3, 57,
69, 23, 9, 2,
34, 11, 5, 99 };
cout<<"My Matrix: "<< endl << endl;
for( x = 0; x < 4; x++)
{
for( y = 0; y < 4; y++)
{
cout<< matrix[x][y] << " ";
}
cout<<endl;
}
cout<< endl <<"Both x and y have a max point of 3" << endl;
do
{
cout<< endl <<"Enter in x and y points[ x <space> y ]: ";
cin>> x1 >> y1;
cout<<"Point ("<< x1 <<", " << y1 <<") = " << matrix[x1][y1] << endl
<< endl;
cout<<"Would You like Output new points (0 to quit)? ";
cin>> repeat;
}while( repeat != 0);
cout<<endl;
cout<<"Press any key to continue";
getch();
return 0;
}
16.Program to Calculate Polynomial. Loading the libraries.
// Program to Calculate Polynoms
//Loading the libraries
#include <iostream.h>
#include <math.h>
#include<conio.h>
//Defining variables
int result=0; //here will be stored the result
int *arr; //here will be stored the numbers
int power; //this is the maximum power
int x; //the value for "x"
//Beginning the main function
void main()
{
cout << "What s the maximum power in the polynom? : ";
cin >> power;
cout << endl;
arr=new int[power]; //creates an array with "power" cells
//Asking the user to enter the values...
for(int n=0;n<power+1;n++)
{
cout <<"A"<<power-n<<" = ";
cin >> arr[power-n];
}
cout << "The polynom is: ";
//Prints the polynom on the screen
for(int go=power; go >-1; go--)
{
if(go > 0)
cout <<arr[go]<<"*x^"<<go<<" + ";
else
cout <<arr[go]<<"*x^"<<go;
}
cout <<endl;
cout <<"Enter value for X : ";
cin >> x;
//Calculating the polynom
for(int cal=0; cal < power+1; cal++)
{
result=result+(arr[cal]*(pow(x,cal)));
}
cout <<" Y(x)= "<< result<<endl; // showing the result
getch();
}
//Loading the libraries
#include <iostream.h>
#include <math.h>
#include<conio.h>
//Defining variables
int result=0; //here will be stored the result
int *arr; //here will be stored the numbers
int power; //this is the maximum power
int x; //the value for "x"
//Beginning the main function
void main()
{
cout << "What s the maximum power in the polynom? : ";
cin >> power;
cout << endl;
arr=new int[power]; //creates an array with "power" cells
//Asking the user to enter the values...
for(int n=0;n<power+1;n++)
{
cout <<"A"<<power-n<<" = ";
cin >> arr[power-n];
}
cout << "The polynom is: ";
//Prints the polynom on the screen
for(int go=power; go >-1; go--)
{
if(go > 0)
cout <<arr[go]<<"*x^"<<go<<" + ";
else
cout <<arr[go]<<"*x^"<<go;
}
cout <<endl;
cout <<"Enter value for X : ";
cin >> x;
//Calculating the polynom
for(int cal=0; cal < power+1; cal++)
{
result=result+(arr[cal]*(pow(x,cal)));
}
cout <<" Y(x)= "<< result<<endl; // showing the result
getch();
}
15.Program to display Fibonaccis Heap
// Program to display Fibonaccis Heap
#include <iostream.h>
#include<conio.h>
void main()
{
clrscr();
unsigned int to,a,n,n1,n2,sum;
cout << "Enter the limit: n=";
cin >> to;
to--;
n1=n2=1;
a=2;
sum=2;
cout << "Fibonacci's numbers: " << endl;
cout << "1 1 ";
while(a<=to)
{
n=n1+n2;
cout << n << " ";
n1=n2; n2=n;
sum=sum+n;
a++;
}
cout << endl << endl ;
cout << "Sum of all numbers= "<< sum << endl;
getch();
}
#include <iostream.h>
#include<conio.h>
void main()
{
clrscr();
unsigned int to,a,n,n1,n2,sum;
cout << "Enter the limit: n=";
cin >> to;
to--;
n1=n2=1;
a=2;
sum=2;
cout << "Fibonacci's numbers: " << endl;
cout << "1 1 ";
while(a<=to)
{
n=n1+n2;
cout << n << " ";
n1=n2; n2=n;
sum=sum+n;
a++;
}
cout << endl << endl ;
cout << "Sum of all numbers= "<< sum << endl;
getch();
}
Subscribe to:
Posts (Atom)
