code for entering a paragraph in C language
How to enter a paragraph in C language?
If you are asking about taking an entire paragraph as input text, then you need to use libraries for the same. Depending on which C you are using:
Turbo C: conio.h
Unix versions: curses.h
Reply:I don't know of such thing in C. Perhaps you're thinking of paragraph in terms of HTML coding? In HTML, %26lt;p%26gt; and %26lt;/p%26gt; are used to enclose a paragraph.
In C, you can manipulate and use the newline special character to do so; that is \n (backslash and the letter n).
Many newline special characters make up many newlines.
Reply:Use \n and \t.
Eg
printf("\tHello, there!\nHow you doin?\nSee ya later");
OUTPUT
Hello, there!
How you doin?
See ya later
\t - TAG SPACE
\n - NEW LINE
Senthil
Tuesday, July 14, 2009
Example program of magic square in c language?
show the whole magic program in c language.
Example program of magic square in c language?
Homework? :-)
See the link to the source below.
Reply:#include "stdafx.h"
#include %26lt;vector%26gt;
using namespace std;
void OddMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void DoublyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void SinglyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void MagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void PrintMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
int main(int argc, char* argv[])
{
int n;
printf("Enter order of square: ");
scanf("%d", %26amp;n);
vector%26lt;vector%26lt;int%26gt; %26gt; matrix(n, vector%26lt;int%26gt; (n, 0));
if (n%26lt;3)
{
printf("\nError: n must be greater than 2\n\n");
return -1;
}
MagicSquare(matrix, n);
//Print results
PrintMagicSquare(matrix, n);
return 0;
}
void MagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix,int n)
{
if (n%2==1) //n is Odd
OddMagicSquare(matrix, n);
else //n is even
if (n%4==0) //doubly even order
DoublyEvenMagicSquare(matrix, n);
else //singly even order
SinglyEvenMagicSquare(matrix, n);
}
void OddMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
int nsqr = n * n;
int i=0, j=n/2; // start position
for (int k=1; k%26lt;=nsqr; ++k)
{
matrix[i][j] = k;
i--;
j++;
if (k%n == 0)
{
i += 2;
--j;
}
else
{
if (j==n)
j -= n;
else if (i%26lt;0)
i += n;
}
}
}
void DoublyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
vector%26lt;vector%26lt;int%26gt; %26gt; I(n, vector%26lt;int%26gt; (n, 0));
vector%26lt;vector%26lt;int%26gt; %26gt; J(n, vector%26lt;int%26gt; (n, 0));
int i, j;
//prepare I, J
int index=1;
for (i=0; i%26lt;n; i++)
for (j=0; j%26lt;n; j++)
{
I[i][j]=((i+1)%4)/2;
J[j][i]=((i+1)%4)/2;
matrix[i][j]=index;
index++;
}
for (i=0; i%26lt;n; i++)
for (j=0; j%26lt;n; j++)
{
if (I[i][j]==J[i][j])
matrix[i][j]=n*n+1-matrix[i][j];
}
}
void SinglyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
int p=n/2;
vector%26lt;vector%26lt;int%26gt; %26gt; M(p, vector%26lt;int%26gt; (p, 0));
MagicSquare(M, p);
int i, j, k;
for (i=0; i%26lt;p; i++)
for (j=0; j%26lt;p; j++)
{
matrix[i][j]=M[i][j];
matrix[i+p][j]=M[i][j]+3*p*p;
matrix[i][j+p]=M[i][j]+2*p*p;
matrix[i+p][j+p]=M[i][j]+p*p;
}
if (n==2)
return;
vector%26lt;int%26gt; I(p, 0);
vector%26lt;int%26gt; J;
for (i=0; i%26lt;p; i++)
I[i]=i+1;
k=(n-2)/4;
for (i=1; i%26lt;=k; i++)
J.push_back(i);
for (i=n-k+2; i%26lt;=n; i++)
J.push_back(i);
int temp;
for (i=1; i%26lt;=p; i++)
for (j=1; j%26lt;=J.size(); j++)
{
temp=matrix[i-1][J[j-1]-1];
matrix[i-1][J[j-1]-1]=matrix[i+p-1][J[j-...
matrix[i+p-1][J[j-1]-1]=temp;
}
//j=1, i
//i=k+1, k+1+p
i=k;
j=0;
temp=matrix[i][j]; matrix[i][j]=matrix[i+p][j]; matrix[i+p][j]=temp;
j=i;
temp=matrix[i+p][j]; matrix[i+p][j]=matrix[i][j]; matrix[i][j]=temp;
}
void PrintMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
for (int i=0; i%26lt;n; i++)
{
for (int j=0; j%26lt;n; j++)
printf(" %3d", matrix[i][j]);
printf("\n");
}
printf("\n\n");
}
love song
Example program of magic square in c language?
Homework? :-)
See the link to the source below.
Reply:#include "stdafx.h"
#include %26lt;vector%26gt;
using namespace std;
void OddMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void DoublyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void SinglyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void MagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
void PrintMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n);
int main(int argc, char* argv[])
{
int n;
printf("Enter order of square: ");
scanf("%d", %26amp;n);
vector%26lt;vector%26lt;int%26gt; %26gt; matrix(n, vector%26lt;int%26gt; (n, 0));
if (n%26lt;3)
{
printf("\nError: n must be greater than 2\n\n");
return -1;
}
MagicSquare(matrix, n);
//Print results
PrintMagicSquare(matrix, n);
return 0;
}
void MagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix,int n)
{
if (n%2==1) //n is Odd
OddMagicSquare(matrix, n);
else //n is even
if (n%4==0) //doubly even order
DoublyEvenMagicSquare(matrix, n);
else //singly even order
SinglyEvenMagicSquare(matrix, n);
}
void OddMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
int nsqr = n * n;
int i=0, j=n/2; // start position
for (int k=1; k%26lt;=nsqr; ++k)
{
matrix[i][j] = k;
i--;
j++;
if (k%n == 0)
{
i += 2;
--j;
}
else
{
if (j==n)
j -= n;
else if (i%26lt;0)
i += n;
}
}
}
void DoublyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
vector%26lt;vector%26lt;int%26gt; %26gt; I(n, vector%26lt;int%26gt; (n, 0));
vector%26lt;vector%26lt;int%26gt; %26gt; J(n, vector%26lt;int%26gt; (n, 0));
int i, j;
//prepare I, J
int index=1;
for (i=0; i%26lt;n; i++)
for (j=0; j%26lt;n; j++)
{
I[i][j]=((i+1)%4)/2;
J[j][i]=((i+1)%4)/2;
matrix[i][j]=index;
index++;
}
for (i=0; i%26lt;n; i++)
for (j=0; j%26lt;n; j++)
{
if (I[i][j]==J[i][j])
matrix[i][j]=n*n+1-matrix[i][j];
}
}
void SinglyEvenMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
int p=n/2;
vector%26lt;vector%26lt;int%26gt; %26gt; M(p, vector%26lt;int%26gt; (p, 0));
MagicSquare(M, p);
int i, j, k;
for (i=0; i%26lt;p; i++)
for (j=0; j%26lt;p; j++)
{
matrix[i][j]=M[i][j];
matrix[i+p][j]=M[i][j]+3*p*p;
matrix[i][j+p]=M[i][j]+2*p*p;
matrix[i+p][j+p]=M[i][j]+p*p;
}
if (n==2)
return;
vector%26lt;int%26gt; I(p, 0);
vector%26lt;int%26gt; J;
for (i=0; i%26lt;p; i++)
I[i]=i+1;
k=(n-2)/4;
for (i=1; i%26lt;=k; i++)
J.push_back(i);
for (i=n-k+2; i%26lt;=n; i++)
J.push_back(i);
int temp;
for (i=1; i%26lt;=p; i++)
for (j=1; j%26lt;=J.size(); j++)
{
temp=matrix[i-1][J[j-1]-1];
matrix[i-1][J[j-1]-1]=matrix[i+p-1][J[j-...
matrix[i+p-1][J[j-1]-1]=temp;
}
//j=1, i
//i=k+1, k+1+p
i=k;
j=0;
temp=matrix[i][j]; matrix[i][j]=matrix[i+p][j]; matrix[i+p][j]=temp;
j=i;
temp=matrix[i+p][j]; matrix[i+p][j]=matrix[i][j]; matrix[i][j]=temp;
}
void PrintMagicSquare(vector%26lt;vector%26lt;int%26gt; %26gt; %26amp;matrix, int n)
{
for (int i=0; i%26lt;n; i++)
{
for (int j=0; j%26lt;n; j++)
printf(" %3d", matrix[i][j]);
printf("\n");
}
printf("\n\n");
}
love song
What the basic example for C programming language?
how to create C language for example record voice and playback....
What the basic example for C programming language?
Are you looking to learn how to write a c program or you know how to program in c and would like to write a program to record voice?
Reply:If you have never programmed before, how do you expect to create such a complicated program as what you are describing? Report It
Reply:Depends on system since these media libs are system specific
What the basic example for C programming language?
Are you looking to learn how to write a c program or you know how to program in c and would like to write a program to record voice?
Reply:If you have never programmed before, how do you expect to create such a complicated program as what you are describing? Report It
Reply:Depends on system since these media libs are system specific
Write a well documented program in c-language to reverse the given no. without using array.?
write a well documented program in c-language to reverse the given no. without using array.e.g. if input is 456 the output should be 654.
Write a well documented program in c-language to reverse the given no. without using array.?
Do your own homework.
Hint: use recursion.
Write a well documented program in c-language to reverse the given no. without using array.?
Do your own homework.
Hint: use recursion.
How to print output in the "C" language programming?
I want to print the output of programme in "C" language
is it possible
How to print output in the "C" language programming?
Look up the printf() function. That is a good place to start.
Oh! wait if you want to take it directly to the printer then if you are on unix then you can just pipe your program to the printer device.
$ myprogram | lpd
On Windows, you could save your output to a file and then print that file with notepad.
c:\dev\myprogram %26gt;output.txt
c:\dev\notepad output.txt
Reply:Here's some examples
printf ("Hello");
cout%26lt;%26lt;"Hello";
int num = 3;
printf("Num : %d",num)
cout%26lt;%26lt;"Num : "%26lt;%26lt;num;
Reply:Print it how? Not to be mean but one of the fascinating things about these answers is how everyone interprets your question differently. I don't think you're irresponsible but it would be nice if you added in additional information whether you want to print it to the screen or to the printer.
I'm on Linux. I have been for a few years and haven't concerned myself with printing to recent iterations of Windows. Both Linux and MS-Dos (the ancestor of Windows) took from Unix the policy of treating everything as a file, even device drivers. Win32 versions like the last ones I did any programming on, continued this. PRN and LPT1 I believe are the names of the printing device in Windows. stdout is the name of the screen in C, period.
Cout is just wrong, if you're asking about C rather than C++. Cout is stdout in the iostream.h library, which is C++, not C. You send variables to it using the %26lt;%26lt; operator, which is also in iostream. What I have to say below applies to a C++ program, once it's compiled.
The C output is usually taken care of by one of 2 functions: printf("format string", variable1, variable2...); or fprintf(Outputdevice, "format string", variable1, variable2...);. You can see how similar they are. Printf is short for PRINT Format. Fprintf is short for File PRINT Format. Printf is the functional equivalent of fprintf(stdout, "format string", ...); Of course you should read the documentation which will tell you among other things, that if you don't have any variables in your format string, you don't need a comma and variable list after, and you only need as many variables in your list as you have indicated in your format string. Most C compilers don't have names for your printer, so if your documentation doesn't indicate one you probably can't make fprintf(PRN...) work. You have two choices. You can use printf or you can open up a file and fprintf your output to the file. Then of course you can send the output file to your printer. In Unix and in older MS/Dos/Windows you can send it a couple of ways. In Unix/Linux just type lpr filename or executable_file %26gt; lpr. In Windows, type executable_file %26gt; prn or print filename. In Windows you will be asked if you want to overwrite prn. Answer yes. Windows treats your prn as a file, but it isn't a file, it's a device, so instead of messing up your driver you will be sending all the characters to the device to print out.
I know this sounds heavy but I'm tired. I hope it helps.
Reply:Use the printf function, which is included in the stdio.h header file.
To include said header file, simply put #include %26lt;stdio.h%26gt; at the very top of your code (this is a preprocessor instruction).
Using printf is simple - it takes a single string argument/parameter, and you can use %d, %f etc to substitute with various variables which can also be passed to the function as extra arguments.
Reply:For Free C++ Lessons For Beginner
Enter Programming_Share Group
Omar Abdallah
is it possible
How to print output in the "C" language programming?
Look up the printf() function. That is a good place to start.
Oh! wait if you want to take it directly to the printer then if you are on unix then you can just pipe your program to the printer device.
$ myprogram | lpd
On Windows, you could save your output to a file and then print that file with notepad.
c:\dev\myprogram %26gt;output.txt
c:\dev\notepad output.txt
Reply:Here's some examples
printf ("Hello");
cout%26lt;%26lt;"Hello";
int num = 3;
printf("Num : %d",num)
cout%26lt;%26lt;"Num : "%26lt;%26lt;num;
Reply:Print it how? Not to be mean but one of the fascinating things about these answers is how everyone interprets your question differently. I don't think you're irresponsible but it would be nice if you added in additional information whether you want to print it to the screen or to the printer.
I'm on Linux. I have been for a few years and haven't concerned myself with printing to recent iterations of Windows. Both Linux and MS-Dos (the ancestor of Windows) took from Unix the policy of treating everything as a file, even device drivers. Win32 versions like the last ones I did any programming on, continued this. PRN and LPT1 I believe are the names of the printing device in Windows. stdout is the name of the screen in C, period.
Cout is just wrong, if you're asking about C rather than C++. Cout is stdout in the iostream.h library, which is C++, not C. You send variables to it using the %26lt;%26lt; operator, which is also in iostream. What I have to say below applies to a C++ program, once it's compiled.
The C output is usually taken care of by one of 2 functions: printf("format string", variable1, variable2...); or fprintf(Outputdevice, "format string", variable1, variable2...);. You can see how similar they are. Printf is short for PRINT Format. Fprintf is short for File PRINT Format. Printf is the functional equivalent of fprintf(stdout, "format string", ...); Of course you should read the documentation which will tell you among other things, that if you don't have any variables in your format string, you don't need a comma and variable list after, and you only need as many variables in your list as you have indicated in your format string. Most C compilers don't have names for your printer, so if your documentation doesn't indicate one you probably can't make fprintf(PRN...) work. You have two choices. You can use printf or you can open up a file and fprintf your output to the file. Then of course you can send the output file to your printer. In Unix and in older MS/Dos/Windows you can send it a couple of ways. In Unix/Linux just type lpr filename or executable_file %26gt; lpr. In Windows, type executable_file %26gt; prn or print filename. In Windows you will be asked if you want to overwrite prn. Answer yes. Windows treats your prn as a file, but it isn't a file, it's a device, so instead of messing up your driver you will be sending all the characters to the device to print out.
I know this sounds heavy but I'm tired. I hope it helps.
Reply:Use the printf function, which is included in the stdio.h header file.
To include said header file, simply put #include %26lt;stdio.h%26gt; at the very top of your code (this is a preprocessor instruction).
Using printf is simple - it takes a single string argument/parameter, and you can use %d, %f etc to substitute with various variables which can also be passed to the function as extra arguments.
Reply:For Free C++ Lessons For Beginner
Enter Programming_Share Group
Omar Abdallah
Help me regarding Computer Ports using C language?
Is there any way of sending a stream of bits from Serial or parallel port of my computer using C language?
Help me regarding Computer Ports using C language?
Try using functions like inport(for reading the port) and outport(for sending data to the port) in dos.h. These functions require a port no. where U want to send the data and the data (binary data converted into decimal, like U wanna active first 4 data pins of Ur parallel port and deactivate the remaining 4 then U can use the data 11110000, which when converted to decimal gives 240, so enter this value along with the port no. while calling the function).
Reply:Yes, in most compilers there are functions called inportB %26amp; outportB that are designed for that. Look in your compiler's docs. Also, you can open a file to either divice using a DOS name in a DOS environment. If, however, you want to create a Win32s API application, then you need to find the API calls to do this. Start at the URL below.
Reply:At codeproject you will find tons of ready projects with full sources.
Reply:Certainly. You write to the port just like writing to a file. That is, you create a handle to the "file" and write to it, then close it. I recommend reading the documentation.
Reply:yes i tcan be done........... but i donno how to do that...........
garden flowers
Help me regarding Computer Ports using C language?
Try using functions like inport(for reading the port) and outport(for sending data to the port) in dos.h. These functions require a port no. where U want to send the data and the data (binary data converted into decimal, like U wanna active first 4 data pins of Ur parallel port and deactivate the remaining 4 then U can use the data 11110000, which when converted to decimal gives 240, so enter this value along with the port no. while calling the function).
Reply:Yes, in most compilers there are functions called inportB %26amp; outportB that are designed for that. Look in your compiler's docs. Also, you can open a file to either divice using a DOS name in a DOS environment. If, however, you want to create a Win32s API application, then you need to find the API calls to do this. Start at the URL below.
Reply:At codeproject you will find tons of ready projects with full sources.
Reply:Certainly. You write to the port just like writing to a file. That is, you create a handle to the "file" and write to it, then close it. I recommend reading the documentation.
Reply:yes i tcan be done........... but i donno how to do that...........
garden flowers
From where can i get software for "c" language?????
Hi i am doing "c" language course.I want the software in which i can practise all the commands and instruction .I mean i have a software called TURBO C++ but it didn't work.please tell me from where i can download it.best answer will be given 15 points.
From where can i get software for "c" language?????
Visual Studio
http://www.microsoft.com/express/vc/
Reply:A great C/C++ IDE to learn with is Dev-C++:
http://www.bloodshed.net/devcpp.html
If you are more of a command-line guy (or just want to get a *nix type feel), try MinGW or Cygwin:
http://www.mingw.org/
http://www.cygwin.com/
If you want the ultimate command-line/native learning experience, install a Linux distro.
Reply:Microsoft releases a free version of Visual C++ .NET you can get info here
http://www.microsoft.com/express/vc/
You can also get a compiler here
http://www.mingw.org/
Hope this helps
Reply:You can download the Tiny C compiler at http://fabrice.bellard.free.fr/tcc/
Other C compilers are listed on Wikipedia:
http://en.wikipedia.org/wiki/List_of_com...
From where can i get software for "c" language?????
Visual Studio
http://www.microsoft.com/express/vc/
Reply:A great C/C++ IDE to learn with is Dev-C++:
http://www.bloodshed.net/devcpp.html
If you are more of a command-line guy (or just want to get a *nix type feel), try MinGW or Cygwin:
http://www.mingw.org/
http://www.cygwin.com/
If you want the ultimate command-line/native learning experience, install a Linux distro.
Reply:Microsoft releases a free version of Visual C++ .NET you can get info here
http://www.microsoft.com/express/vc/
You can also get a compiler here
http://www.mingw.org/
Hope this helps
Reply:You can download the Tiny C compiler at http://fabrice.bellard.free.fr/tcc/
Other C compilers are listed on Wikipedia:
http://en.wikipedia.org/wiki/List_of_com...
Subscribe to:
Posts (Atom)