Output:
Experiment No: 9
Write a program to input 2 strings from the user and to print out
(i) the concatenation of the two strings with a space between them,
(ii) a line of asterisks the same length as the concatenated strings, and
(iii) the reversed concatenation.
(iv) ************* v. elavkcuH kraM
Code
:
a)
x="hello ";
y="man";
a=[x,y]
b)
x="hello ";
y="man";
len=length(a)
for i=1:len
ast(i)="*";
end
ast
c)
x="hello ";
y="man";
a=strcat(x,y)
d)
x="hello ";
y="man";
a={x,y}
fliplr(a)
Output
Experiment No: 11
where the square brackets mean take the integer part, modulo 7 means the remainder
when divided by 7, and i. d = day of the month (e.g. 1 to 31) ii. m = month number with
March=1, ..., December=10, January=11, 1. February=12. Assign January and February
to the previous year. iii. c = century number (e.g. 19) iv. y = year in century (e.g. 97), but
remember January and February
function weekday=dayofweek(d)
month=1+rem(d(2)+9,12);
year=d(3)-fix(month/11);
century=fix(year/100);
year=rem(year,100);
day=d(1);
val=fix(2.6*month-0.2)+day+year+fix(year/4)+fix(century/4)-2*century;
wday=1+rem(28+val,7);
days=['Sunday ';'Monday ';'Tuesday ';'Wednesday';'Thursday ';'Friday ';'Saturday '];
weekday=days(wday,:);
Output:
octave:2> my_script([12 02 2022])
ans = Saturday
13
Experiment No: 11
AIM: -Write a program that asks for a series the sum and the mean. For example: of
numbers, ending in the value 0, and calculates
a. Enter a number (end in 0): 5
b. Enter a number (end in 0): 6
c. Enter a number (end in 0) : 7
d. Enter a number (end in 0) : 8
e. Enter a number (end in 0) : 0
f. 4 numbers entered. Sum=26. Mean=6.5
function Avg = Average()
Num = input('Enter the array of Numbers : *);
Len = length(Num);
sum=0;
for i=1 : Len
sum = sum + Num(i);
end
disp('Sum of Number is');
disp(sum);
Avg sum/Len;
disp('Average of Number is');
disp(Avg);
Output:
Enter the array of Numbers: > [2 8]
Sum of Number is 10
Average of Number is 5
ans = 5
Experiment No: 12
AIM: - Test your function by sorting a list of random numbers. (Hint: you will need a
while loop inside a for loop).
Program:
function y : sort(x)
n = length(x);
if n<2
y-X;
return;
end
for i=1:n-l
if x0>x(i+1)
temp=x(i);
x(i)= x(i+1)
x(i+1)-temp;
end
end
y = sort(x(1:n-1));
y= [y x(n)]:
end
Output:-
octave: 0> array = [ 2 4 12 7 1]
array = 2 4 12 7 1
octave:2> sort (array)
ans: 1 2 4 7 12
2>
Do'stlaringiz bilan baham: |