Академический Документы
Профессиональный Документы
Культура Документы
1410991703
EXP 1 :- Write a Program to calculate the average of value stored in three
integer variable
and display it correctly upto two decimal places .
CODE :
1410991703
EXP 2 :- Write a swap() function that uses pass-by-Reference to swap
values of two variables
declared in the main function
CODE :
1410991703
EXP 3 :- Write a program that reads two strings 's1' and 's2' from keyboard
and counts the
occurrence of string 's2' from 's1'
CODE :
//Abhishek Kansal ECE 140991703
#include <iostream>
#include<cstring>
using namespace std;
int main()
{
char s1[100], s2[100];
int count = 0, count1 = 0;
int i, j, l1, l2;
cout<<"Enter the S1:"<<endl;
cin.get(s1,100);
l1 = strlen(s1);
s1[l1]='m';s1[l1+1]=NULL;
cout<<"Enter the S2:"<<endl;
cin>>s2;
l2 = strlen(s2);
for (i = 0; i < l1;)
{
j = 0;
count = 0;
while ((s1[i] == s2[j]))
{
count++;
i++;
j++;
}
if (count == l2)
{
1410991703
count1++;
count = 0;
}
else
i++;
}
cout<<"substring occurs in main string "<<count1<<" times";
return 0;
}
OUTPUT :
1410991703
EXP 4 :- Write a program that allocates memory dynamically to a 2D
array , reads values in it
from keyboard and then applies the transpose function on it.
verify the result by
displaying 2D array on screen
CODE :
1410991703
{
for (j = 0; j < ncolumns; j++)
{ cout<<array[i][j]<<" ";}
cout<<endl;
}
for (i = 0; i < nrows; i++)
{for (j = 0; j < ncolumns; j++)
{trans[j][i]=array[i][j];
}
}
cout<<"transposed 2-D array:"<<endl;
for (i = 0; i < nrows; i++)
{
for (j = 0; j < ncolumns; j++)
{ cout<<trans[i][j]<<" ";}
cout<<endl;
}
return 0;
}
OUTPUT :