diff --git a/12 may assigment 2/copy_string.cpp b/12 may assigment 2/copy_string.cpp new file mode 100644 index 0000000..8d4a4c3 --- /dev/null +++ b/12 may assigment 2/copy_string.cpp @@ -0,0 +1,29 @@ +//copy string without strcpy + +#include +#include + +int main() +{ + char Str[100], CopyStr[100]; + int i; + + printf("\n Enter any String : "); + gets(Str); + + for (i = 0; Str[i]!='\0'; i++) + { + CopyStr[i] = Str[i]; + } + CopyStr[i] = '\0'; + + printf("\n String that we coped into CopyStr = %s", CopyStr); + printf("\n Total Number of Characters that we copied = %d\n", i); + + return 0; +} +//output +//enter any string: happy +//string we copied in copystr = happy +//total number of characters that we copied = 5 + diff --git a/12 may assigment 2/coversion_of_no.cpp b/12 may assigment 2/coversion_of_no.cpp new file mode 100644 index 0000000..5218416 --- /dev/null +++ b/12 may assigment 2/coversion_of_no.cpp @@ -0,0 +1,23 @@ +// Program to convert Decimal to Binary + +#include +using namespace std; +int main() +{ +int a[10], n, i; +cout<<"Enter the number to convert: "; +cin>>n; +for(i=0; n>0; i++) +{ +a[i]=n%2; +n= n/2; +} +cout<<"Binary of the given number= "; +for(i=i-1 ;i>=0 ;i--) +{ +cout< +#include +using namespace std; +int main() +{ + char str1[20], str2[20]; + int i, j, len = 0, flag = 0; + cout << "Enter the string : "; + gets(str1); + len = strlen(str1) - 1; + for (i = len, j = 0; i >= 0 ; i--, j++) + str2[j] = str1[i]; + if (strcmp(str1, str2)) + flag = 1; + if (flag == 1) + cout << str1 << " is not a palindrome"; + else + cout << str1 << " is a palindrome"; + return 0; +} + +//output: +//Enter the string:abba +//abba is a palindrome diff --git a/12 may assigment 2/remove_duplicates.cpp b/12 may assigment 2/remove_duplicates.cpp new file mode 100644 index 0000000..502fc85 --- /dev/null +++ b/12 may assigment 2/remove_duplicates.cpp @@ -0,0 +1,38 @@ +// C++ Program to Delete Repeated Elements + +#include +using namespace std; +int main () +{ + int A[10], B[10], n, i, j, k = 0; + cout << "Enter size of array : "; + cin >> n; + cout << "Enter elements of array : "; + for (i = 0; i < n; i++) + cin >> A[i]; + for (i = 0; i < n; i++) + { + for (j = 0; j < k; j++) + { + if (A[i] == B[j]) + break; + } + if (j == k) + { + B[k] = A[i]; + k++; + } + } + cout << "Repeated elements after deletion : "; + for (i = 0; i < k; i++) + cout << B[i] << " "; + return 0; +} + +//output: +//Enter size of array: 4 +//Enter elemnts of array: 11 +//32 +//45 +//11 +//repeated elements after deletion : 11 32 45 diff --git a/12 may assigment 2/search.cpp b/12 may assigment 2/search.cpp new file mode 100644 index 0000000..8664032 --- /dev/null +++ b/12 may assigment 2/search.cpp @@ -0,0 +1,45 @@ +// Write a C++ program to search any element in an array. + + +#include +using namespace std; + +int main() +{ + int arr[10], i, num, n, cnt=0, pos; + cout<<"\n Enter Array Size : "; + cin>>n; + cout<<"\n Enter Array Elements : \n"; + for(i=0; i>arr[i]; + } + cout<<"\n Enter Element to be Searched : "; + cin>>num; + for(i=0; i +using namespace std; + +int findSingle(int ar[], int ar_size) + { + int res = ar[0]; + for (int i = 1; i < ar_size; i++) + res = res ^ ar[i]; + + return res; + } + +int main() + { + int ar[] = {2, 3, 5, 4, 5, 3, 4}; + int n = sizeof(ar) / sizeof(ar[0]); + cout << "element occuring once is " + << findSingle(ar , n); + return 0; + } + +// output is : element occuring once is 2 diff --git a/assigment 1 (11 may 2020)/Ques1 (1).exe b/assigment 1 (11 may 2020)/Ques1 (1).exe new file mode 100644 index 0000000..5e2179e Binary files /dev/null and b/assigment 1 (11 may 2020)/Ques1 (1).exe differ diff --git a/assigment 1 (11 may 2020)/Ques4 (1).cpp b/assigment 1 (11 may 2020)/Ques4 (1).cpp new file mode 100644 index 0000000..2ef3c95 --- /dev/null +++ b/assigment 1 (11 may 2020)/Ques4 (1).cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int numberOfPaths(int m, int n) +{ + if (m == 1 || n == 1) + return 1; + + return numberOfPaths(m - 1, n) + numberOfPaths(m, n - 1); +} + +int main() +{ + cout << numberOfPaths(3, 3); + return 0; +} + +// output is 6 + diff --git a/assigment 1 (11 may 2020)/Ques4 (1).exe b/assigment 1 (11 may 2020)/Ques4 (1).exe new file mode 100644 index 0000000..7d2e076 Binary files /dev/null and b/assigment 1 (11 may 2020)/Ques4 (1).exe differ diff --git a/assigment 1 (11 may 2020)/Question3 (1).cpp b/assigment 1 (11 may 2020)/Question3 (1).cpp new file mode 100644 index 0000000..d7ad5bb --- /dev/null +++ b/assigment 1 (11 may 2020)/Question3 (1).cpp @@ -0,0 +1,40 @@ +#include +using namespace std; + +int solve(int low, int high, int T) +{ + while (low <= high) + { + int mid = (low + high) / 2; + + if ((mid * (mid + 1)) == T) + return mid; + + if (mid > 0 && (mid * (mid + 1)) > T && + (mid * (mid - 1)) <= T) + return mid - 1; + + if ((mid * (mid + 1)) > T) + high = mid - 1; + + else + low = mid + 1; + } + return -1; +} + +int main() +{ + int T = 15; + + int ans = solve(1, T, 2 * T); + + if (ans != -1) + ans--; + + cout << "Number of stair steps = " + << ans << endl; + return 0; +} + +// output is Number of stair steps = 4 diff --git a/assigment 1 (11 may 2020)/Question3 (1).exe b/assigment 1 (11 may 2020)/Question3 (1).exe new file mode 100644 index 0000000..82c4236 Binary files /dev/null and b/assigment 1 (11 may 2020)/Question3 (1).exe differ diff --git a/assigment 1 (11 may 2020)/qu5 (3).cpp b/assigment 1 (11 may 2020)/qu5 (3).cpp new file mode 100644 index 0000000..b935d1d --- /dev/null +++ b/assigment 1 (11 may 2020)/qu5 (3).cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +double Square(double n, double i, double j) +{ + double mid = (i + j) / 2; + double mul = mid * mid; + + + if ((mul == n) || (abs(mul - n) < 0.00001)) + return mid; + + else if (mul < n) + return Square(n, mid, j); + + else + return Square(n, i, mid); +} + +void findSqrt(double n) +{ + double i = 1; + + bool found = false; + while (!found) { + + if (i * i == n) { + cout << fixed << setprecision(0) << i; + found = true; + } + else if (i * i > n) { + + double res = Square(n, i - 1, i); + cout << fixed << setprecision(5) << res; + found = true; + } + i++; + } +} + +int main() +{ + double n = 7; + + findSqrt(n); + + return 0; +} +//output is 2.4575 diff --git a/assigment 1 (11 may 2020)/qu5 (3).exe b/assigment 1 (11 may 2020)/qu5 (3).exe new file mode 100644 index 0000000..021645d Binary files /dev/null and b/assigment 1 (11 may 2020)/qu5 (3).exe differ diff --git a/assigment 1 (11 may 2020)/que2 (1).cpp b/assigment 1 (11 may 2020)/que2 (1).cpp new file mode 100644 index 0000000..841a069 --- /dev/null +++ b/assigment 1 (11 may 2020)/que2 (1).cpp @@ -0,0 +1,38 @@ +#include + +int PathCounting(int m, int n) +{ + int ctr[m][n]; + for (int i = 0; i < m; i++) + { + ctr[i][0] = 1; + } + for (int j = 0; j < n; j++) + { + ctr[0][j] = 1; + } + for (int i = 1; i < m; i++) + { + for (int j = 1; j < n; j++) + { + ctr[i][j] = ctr[i-1][j] + ctr[i][j-1]; + } + } + return ctr[m-1][n-1]; +} + +int main() +{ + int p,q; + printf("enter no. of rows of matrix "); + scanf("%d",&p); + printf("enter no. of column of matrix "); + scanf("%d",&q); + printf("The size of matrix is : %d, %d\n",p,q); + printf("The all possible paths from top left to bottom right is: %d \n",PathCounting(p,q)); +} +// output is +// enter no. of rows of matrix 3 +// enter no. of column of matrix 4 +// The size of matrix is : 3, 4 +// The all possible paths from top left to bottom right is: 10 diff --git a/assigment 1 (11 may 2020)/que2 (2).exe b/assigment 1 (11 may 2020)/que2 (2).exe new file mode 100644 index 0000000..17f564c Binary files /dev/null and b/assigment 1 (11 may 2020)/que2 (2).exe differ diff --git a/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/copy_string.cpp b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/copy_string.cpp new file mode 100644 index 0000000..8d4a4c3 --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/copy_string.cpp @@ -0,0 +1,29 @@ +//copy string without strcpy + +#include +#include + +int main() +{ + char Str[100], CopyStr[100]; + int i; + + printf("\n Enter any String : "); + gets(Str); + + for (i = 0; Str[i]!='\0'; i++) + { + CopyStr[i] = Str[i]; + } + CopyStr[i] = '\0'; + + printf("\n String that we coped into CopyStr = %s", CopyStr); + printf("\n Total Number of Characters that we copied = %d\n", i); + + return 0; +} +//output +//enter any string: happy +//string we copied in copystr = happy +//total number of characters that we copied = 5 + diff --git a/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/coversion_of_no.cpp b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/coversion_of_no.cpp new file mode 100644 index 0000000..5218416 --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/coversion_of_no.cpp @@ -0,0 +1,23 @@ +// Program to convert Decimal to Binary + +#include +using namespace std; +int main() +{ +int a[10], n, i; +cout<<"Enter the number to convert: "; +cin>>n; +for(i=0; n>0; i++) +{ +a[i]=n%2; +n= n/2; +} +cout<<"Binary of the given number= "; +for(i=i-1 ;i>=0 ;i--) +{ +cout< +#include +using namespace std; +int main() +{ + char str1[20], str2[20]; + int i, j, len = 0, flag = 0; + cout << "Enter the string : "; + gets(str1); + len = strlen(str1) - 1; + for (i = len, j = 0; i >= 0 ; i--, j++) + str2[j] = str1[i]; + if (strcmp(str1, str2)) + flag = 1; + if (flag == 1) + cout << str1 << " is not a palindrome"; + else + cout << str1 << " is a palindrome"; + return 0; +} + +//output: +//Enter the string:abba +//abba is a palindrome diff --git a/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/remove_duplicates.cpp b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/remove_duplicates.cpp new file mode 100644 index 0000000..502fc85 --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/remove_duplicates.cpp @@ -0,0 +1,38 @@ +// C++ Program to Delete Repeated Elements + +#include +using namespace std; +int main () +{ + int A[10], B[10], n, i, j, k = 0; + cout << "Enter size of array : "; + cin >> n; + cout << "Enter elements of array : "; + for (i = 0; i < n; i++) + cin >> A[i]; + for (i = 0; i < n; i++) + { + for (j = 0; j < k; j++) + { + if (A[i] == B[j]) + break; + } + if (j == k) + { + B[k] = A[i]; + k++; + } + } + cout << "Repeated elements after deletion : "; + for (i = 0; i < k; i++) + cout << B[i] << " "; + return 0; +} + +//output: +//Enter size of array: 4 +//Enter elemnts of array: 11 +//32 +//45 +//11 +//repeated elements after deletion : 11 32 45 diff --git a/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/search.cpp b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/search.cpp new file mode 100644 index 0000000..8664032 --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/12 may assigment 2/search.cpp @@ -0,0 +1,45 @@ +// Write a C++ program to search any element in an array. + + +#include +using namespace std; + +int main() +{ + int arr[10], i, num, n, cnt=0, pos; + cout<<"\n Enter Array Size : "; + cin>>n; + cout<<"\n Enter Array Elements : \n"; + for(i=0; i>arr[i]; + } + cout<<"\n Enter Element to be Searched : "; + cin>>num; + for(i=0; i +using namespace std; + +int findSingle(int ar[], int ar_size) + { + int res = ar[0]; + for (int i = 1; i < ar_size; i++) + res = res ^ ar[i]; + + return res; + } + +int main() + { + int ar[] = {2, 3, 5, 4, 5, 3, 4}; + int n = sizeof(ar) / sizeof(ar[0]); + cout << "element occuring once is " + << findSingle(ar , n); + return 0; + } + +// output is : element occuring once is 2 diff --git a/shivraj singh/assigment 1 (11 may 2020)/Ques1 (1).exe b/shivraj singh/assigment 1 (11 may 2020)/Ques1 (1).exe new file mode 100644 index 0000000..5e2179e Binary files /dev/null and b/shivraj singh/assigment 1 (11 may 2020)/Ques1 (1).exe differ diff --git a/shivraj singh/assigment 1 (11 may 2020)/Ques4 (1).cpp b/shivraj singh/assigment 1 (11 may 2020)/Ques4 (1).cpp new file mode 100644 index 0000000..2ef3c95 --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/Ques4 (1).cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int numberOfPaths(int m, int n) +{ + if (m == 1 || n == 1) + return 1; + + return numberOfPaths(m - 1, n) + numberOfPaths(m, n - 1); +} + +int main() +{ + cout << numberOfPaths(3, 3); + return 0; +} + +// output is 6 + diff --git a/shivraj singh/assigment 1 (11 may 2020)/Ques4 (1).exe b/shivraj singh/assigment 1 (11 may 2020)/Ques4 (1).exe new file mode 100644 index 0000000..7d2e076 Binary files /dev/null and b/shivraj singh/assigment 1 (11 may 2020)/Ques4 (1).exe differ diff --git a/shivraj singh/assigment 1 (11 may 2020)/Question3 (1).cpp b/shivraj singh/assigment 1 (11 may 2020)/Question3 (1).cpp new file mode 100644 index 0000000..d7ad5bb --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/Question3 (1).cpp @@ -0,0 +1,40 @@ +#include +using namespace std; + +int solve(int low, int high, int T) +{ + while (low <= high) + { + int mid = (low + high) / 2; + + if ((mid * (mid + 1)) == T) + return mid; + + if (mid > 0 && (mid * (mid + 1)) > T && + (mid * (mid - 1)) <= T) + return mid - 1; + + if ((mid * (mid + 1)) > T) + high = mid - 1; + + else + low = mid + 1; + } + return -1; +} + +int main() +{ + int T = 15; + + int ans = solve(1, T, 2 * T); + + if (ans != -1) + ans--; + + cout << "Number of stair steps = " + << ans << endl; + return 0; +} + +// output is Number of stair steps = 4 diff --git a/shivraj singh/assigment 1 (11 may 2020)/Question3 (1).exe b/shivraj singh/assigment 1 (11 may 2020)/Question3 (1).exe new file mode 100644 index 0000000..82c4236 Binary files /dev/null and b/shivraj singh/assigment 1 (11 may 2020)/Question3 (1).exe differ diff --git a/shivraj singh/assigment 1 (11 may 2020)/qu5 (3).cpp b/shivraj singh/assigment 1 (11 may 2020)/qu5 (3).cpp new file mode 100644 index 0000000..b935d1d --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/qu5 (3).cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +double Square(double n, double i, double j) +{ + double mid = (i + j) / 2; + double mul = mid * mid; + + + if ((mul == n) || (abs(mul - n) < 0.00001)) + return mid; + + else if (mul < n) + return Square(n, mid, j); + + else + return Square(n, i, mid); +} + +void findSqrt(double n) +{ + double i = 1; + + bool found = false; + while (!found) { + + if (i * i == n) { + cout << fixed << setprecision(0) << i; + found = true; + } + else if (i * i > n) { + + double res = Square(n, i - 1, i); + cout << fixed << setprecision(5) << res; + found = true; + } + i++; + } +} + +int main() +{ + double n = 7; + + findSqrt(n); + + return 0; +} +//output is 2.4575 diff --git a/shivraj singh/assigment 1 (11 may 2020)/qu5 (3).exe b/shivraj singh/assigment 1 (11 may 2020)/qu5 (3).exe new file mode 100644 index 0000000..021645d Binary files /dev/null and b/shivraj singh/assigment 1 (11 may 2020)/qu5 (3).exe differ diff --git a/shivraj singh/assigment 1 (11 may 2020)/que2 (1).cpp b/shivraj singh/assigment 1 (11 may 2020)/que2 (1).cpp new file mode 100644 index 0000000..841a069 --- /dev/null +++ b/shivraj singh/assigment 1 (11 may 2020)/que2 (1).cpp @@ -0,0 +1,38 @@ +#include + +int PathCounting(int m, int n) +{ + int ctr[m][n]; + for (int i = 0; i < m; i++) + { + ctr[i][0] = 1; + } + for (int j = 0; j < n; j++) + { + ctr[0][j] = 1; + } + for (int i = 1; i < m; i++) + { + for (int j = 1; j < n; j++) + { + ctr[i][j] = ctr[i-1][j] + ctr[i][j-1]; + } + } + return ctr[m-1][n-1]; +} + +int main() +{ + int p,q; + printf("enter no. of rows of matrix "); + scanf("%d",&p); + printf("enter no. of column of matrix "); + scanf("%d",&q); + printf("The size of matrix is : %d, %d\n",p,q); + printf("The all possible paths from top left to bottom right is: %d \n",PathCounting(p,q)); +} +// output is +// enter no. of rows of matrix 3 +// enter no. of column of matrix 4 +// The size of matrix is : 3, 4 +// The all possible paths from top left to bottom right is: 10 diff --git a/shivraj singh/assigment 1 (11 may 2020)/que2 (2).exe b/shivraj singh/assigment 1 (11 may 2020)/que2 (2).exe new file mode 100644 index 0000000..17f564c Binary files /dev/null and b/shivraj singh/assigment 1 (11 may 2020)/que2 (2).exe differ