Saturday, May 31, 2014

Standard Input/Output Examples in C,C++,Pascal

Standard Input/Output :

 UNIX programmers are familiar with notions of filters and pipes–programs that take
one stream of input and produce one stream of output. The output of such programs
is suitable to feed to other programs as input. The paradigm is one of stringing lots of
little programs together rather than producing big, complicated software systems that
try to do everything.
This software tools philosophy has taken somewhat of a beating in recent years due
to the popularity of graphical user interfaces. Many programmers instinctively put a
point-and-click interface on every program. But such interfaces can make it very difficult
to transfer data from one program to another. It is easy to manipulate text output in
another program, but what can you do with an image other than look at it?


C Code:
#include<stdio.h>
int main() {
long p,q,r;
while (scanf("%ld %ld",&p,&q)
!=EOF) {
if (q>p) r=q-p;
else r=p-q;
printf("%ld\n",r);
}
}

C++ Code:
#include<iostream.h>
void main()
{
long long a,b,c;
while (cin>>a>>b) {
if (b>a)
c=b-a;
else
c=a-b;
cout << c << endl;

Pascal Code:
{$N+}
program acm;
var
a, b, c : integer;
begin
while not eof do
begin
readln(a, b);
if b > a then
begin
c := b;
b := a;
a := c
end;
writeln(a - b);
end
end.

By Im@n

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home