Professional Documents
Culture Documents
CODE:
print "How many i/p does your Design have: ";
chomp ($ip_no=<STDIN>);
print "How many set of data you want to genarate: ";
chomp ($set_no=<STDIN>);
for ($i=1;$i<=$ip_no;$i++)
{
print "\nPlease enter the no. $i input's name: ";
chomp ($ip_name[$i]=<STDIN>);
print "\nPlease enter the no. $i input's size(In Bits): ";
chomp ($ip_size[$i]=<STDIN>);
}
OUTPUT:
4. Write a Perl program so that when it is executed, it should get the information like names and marks of "N"
number of students from the user through the standard input. Value of N (Number of students) should be passed
through command line argument. Make an associative array that has a list of all the names of the students and their
marks. Also write a subroutine so that it calculates the average marks of all the entries in the associative array.
CODE:
($in)=@ARGV[0];
for ($i=0;$i<$in;$i=$i+1)
{
$no=$i+1;
print "Please enter No.$no student's name: ";
chomp($name=<STDIN>);
print "Please enter $name 's Mark: ";
chomp($mark=<STDIN>);
$students{$name}=$mark;
}
@names=keys%students;
@marks=values%students;
print "\n\nNAMES\t\tMARKS\n---------------------\n";
for ($j=0;$j<$in;$j=$j+1)
{
print "@names[$j]\t\t@marks[$j]\n";
}
print "\n";
avg_marks();
print "\n";
sub avg_marks
{
$sum=0;
for ($i=0;$i<$in;$i=$i+1)
{
$value = @marks[$i];
$sum=$sum+$value;
}
$avg=$sum/$in;
printf "Avg marks of all students is: %.2f\n",$avg;
}
OUTPUT: