Sei sulla pagina 1di 9

C:

1. Save the program with extension *.c


2. Go to folder containing program in cmd
3. To execute the program gcc -o programname programname.c
4. To run the program ./programname (no extension *.c)
5 . To take the input from file :
./programname filename1.txt filename1.txt
Otherwise you may get segmentation fault.
STL:
1. Save the program with extension *.cpp
2. To compile the program- go to folder where the program exists
3. type
g++ programname.cpp
4. In the folder, you can find a.out
5. To run the program, type ./a.out in cmd
Model Programs:
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
#include<queue>
int main()
{
queue<int> q1;
int i,k,j;
cout<<"Enter first person to hold the knife:"<<" ";
scanf("%d", &j);
if(j<=100)
{
for(i=j;i<=j+99;i++)
{
q1.push(i);
}
/*for(i=1;i<=100;i++)
{
printf("%d\n",q1.front());
q1.pop();
}*/
while(q1.size()>=2)
{
k=q1.front();
q1.pop();
q1.pop();

q1.push(k);
}
cout<<"**Person alive at the end:"<<" ";
cout<<k%100<<endl;
}
else cout<<"Invalid input\n"<<" ";
return 0;
}
*------------------------------------------------------------------------------------------------------------------------*

#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
#include<queue>
int main()
{
queue<string> q1;
int n;
string s1,s2,s3;
q1.push("a");
q1.push("b");
q1.push("c");
cout<<"Enter no.of elements to print"<<endl;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
s1 = s2= s3 = q1.front();
printf("%s\n",s1.c_str());
//cout<<s1<<" ";
q1.pop();
s1.append("a");
s2.append("b");
s3.append("c");
q1.push(s1); q1.push(s2);q1.push(s3);
}
return 0;
}
*---------------------------------------------------------------------------------------------------------------------- *

#include<iostream>
using namespace std;
#include<queue>
int main()
{
queue<int> Q;
Q.push(10);
Q.push(20);
Q.push(30);
printf("%d \n", Q.front());
Q.pop();
Q.push(40);
printf("%d \n",Q.front());
printf("Size of the queue is %d",Q.size());
if(Q.empty())
cout<<"Queue is empty"<<endl;
else
cout<<"Queue is not empty"<<endl;
return 0;
}
*-----------------------------------------------------------------------------------------------------------------------*

BASH
1. Save the program with extension *.sh
2. Go to folder containing the program in cmd
3. to run and execute type bash *.sh in cmd
Sample programs:
clear
echo "**Program for Printing a pyramid**"
read -p "Enter Number:" number
#Outer loop for printing number of rows in pyramid
for((row=1;row<=number;row++))

do
#Loop for printing required spaces
for((spaces=row;spaces<=number;spaces++))
do
echo -ne " "
done
#Loop for printing 1st part
for((j=1;j<=row;j++))
do
echo -ne " $j"
done
#Loop for printing 2nd part
for((l=(row-1);l>=1;l--))
do
echo -ne " $l"
done
#echo for printing new line
echo
done
*------------------------------------------------------------------------------------------------------------------------*
#Taking input
clear
echo "** Program for printing Pattern**"
read -p "Enter Number:" number
for((row=0;row<=number;row++))
do
for((j=row;j>=0;j--))
do
echo -ne " $j"
done
echo # used to go to next line
done
*------------------------------------------------------------------------*
clear
echo "**Program for Printing armstrong number**"
read -p "Enter starting number:" start
read -p "Enter last number:" end
for((a=$start;a<=$end;a++))
do

temp=$a
num=$a
sum1=0
rem=0
while((temp>0))
do
rem=$((temp%10))
sum1=$((sum1 + rem*rem*rem))
temp=$((temp/10))
done
if((sum1==num)); then
echo "$num"
fi
i=$((i+1))
done
*-----------------------------------------------------------------------------------------*
clear
echo "**Program for ckeck a[0]+a[2]=a[1]**"
read -p "Enter the number:" num
temp=$num
sum1=0
rem=0
rem=$((temp%10))
sum1=$((sum1 + rem))
temp=$((temp/10))
rem=$((temp%10))
a=$rem;
temp=$((temp/10))
#rem=$((temp%10))
sum1=$((sum1 + temp))
if((sum1==a)); then
echo "Satisfying"
else echo "NOT Satisfying"
fi
*--------------------------------------------------------------------------------------------------------*
clear
echo "**Program for Printing pythogorean triplets**"
sd=0
sum=0
for((a=1;a<=100;a++))

do
for((b=1;b<=100;b++))
do
for((c=1;c<=100;c++))
do
sd=$(( $a*$a+$b*$b))
if((sd==$c*$c)); then
echo "$a $b $c"
fi
done
done
done
*----------------------------------------------------------------------------------------------*
clear
echo "**Program for Printing pythogorean triplets-consecutive numbers**"
sq=0
for((a=1;a<=200;a++))
do
for((b=1;b<=200;b++))
do
for((c=1;c<=200;c++))
do
sq=$(( $a*$a+$b*$b))
if((sq==$c*$c)); then
if(($a==$b+1||$b==$c+1||$c==$a+1)); then
echo -e "$a $b $c"
fi
fi
done
done
done
*-----------------------------------------------------------------------------------------------------------------*
AWK:
1. save program with extension *.csh
2. go to concerned folder in cmd
3. to execute chmod +x *.csh
4. To run ./*.csh

GNU Plot:
1. open gnuplot by typing gnuplot in cmd
2. open text file, write the program and save it as *.gnuplot.
3. load *.gnuplot using load '*.gnuplot' command in cmd
# Some example commands for basic gnuplot
plot sin(x) # basic plot command, plots sine function(random x,y)
##
set xrange[0:2*pi]; # set x-axis from 0 to 2*pi
set yrange[-1:1]; # set y-axis from -1 to -1
plot sin(x);
##
##
replot cos(x); # plots cos function on the previous graph(over writes)
##
##
set title "GENERAL SINE/COS FUNCTIONS"; # Title
set xlabel "Angle(in radians)";
# X axis label
set ylabel "Amplitude";
# Y axis label
plot sin(x);
replot cos(x);
##
##
set xrange[0:2*pi]; # set x-axis from 0 to 2*pi
set yrange[-1:1]; # set y-axis from -1 to -1
set title "GENERAL SINE/COS FUNCTIONS";
set xlabel "Angle(in radians)";
set ylabel "Amplitude";
splot sin(x);
# 2-dimentional projection on 3D graph
replot cos(x);
##
##
set xrange[0:1000]; # set x-axis from 0 to 1000
set yrange[0.4:0.6]; # set y-axis from 0.4 to 0.6
set title "Esimated Mean";
set xlabel "No.of Samples";
set ylabel "Mean";
plot 'ganesh.xls' w l; # takes data from file ganesh.xls, plot the graph for first two columns. w l- all

points will be joined with line


# (Line Plot)
##

##
set xrange[0:1000]; # set x-axis from 0 to 1000
set yrange[0.4:0.6]; # set y-axis from 0.4 to 0.6
set title "Esimated Mean";
set xlabel "No.of Samples";
set ylabel "Mean";
plot 'ganesh.xls'; # takes data from file ganesh.xls, plot the graph for first two columns.all points will
be denoted with +(Scatter plot)
##

##
set xrange[0:1000];
set xtics 50;
# defines tick marks at each 50 on x-axis
set yrange[0.4:0.6];
set ytics .05;
# defines tick marks at each 50 on y-axis
set title "Esimated Mean";
set xlabel "No.of Samples";
set ylabel "Mean";
plot 'ganesh.xls';
unset xtics;
unset ytics;
##
##
set xrange[0:2*pi];
set yrange[-1:1];
set title "plotting two functions";
set xlabel "time";
set ylabel "amplitude";
f1(x)= sin(x); # definig a function f1
f2(x)=cos(x); # definig another function f2
plot f1(x) t "Sin(x)",f2(x) t "Cos(x)"; # plotting two function on a same graph, t "Sin(x)"& t "Cos(x)"
gives legend to the graph
unset xrange;
unset yrange;
##
##
set terminal png;
set output '2.png';
set parametric ;

# Drawing a circle .In the parametric mode, the variable is t (instead of x).

set trange [-pi:pi];


plot sin(t),cos(t);
unset parametric;
##
##
set terminal png;
set output '1.png';
set xrange[0:2*pi];
set yrange[-1:1];
set title "plotting two functions";
set xlabel "time";
set ylabel "amplitude";
f1(x)= sin(x); # definig a function f1
f2(x)=cos(x); # definig another function f2
plot f1(x) t "Sin(x)",f2(x) t "Cos(x)"; # plotting two function on a same graph, t "Sin(x)"& t "Cos(x)"
gives legend to the graph
unset xrange;
unset yrange;
##

Potrebbero piacerti anche