├── All Assignments Questions Links ├── Assignment-01.txt ├── Assignment-02.txt ├── Assignment-03.txt ├── Assignment-04.txt ├── Assignment-05.txt ├── Assignment-06.txt ├── Assignment-07.txt ├── Assignment-08.txt ├── Assignment-09.txt ├── Assignment-10.txt ├── Assignment-11.txt ├── Assignment-12.txt ├── Assignment-13.txt ├── Assignment-14.txt ├── Assignment-15.txt ├── Assignment-16.txt ├── Assignment-17.txt ├── Assignment-18.txt ├── Assignment-19.txt ├── Assignment-20.txt ├── Assignment-21.txt ├── Assignment-22.txt ├── Assignment-23.txt ├── Assignment-24.txt └── Assignment-25.txt ├── C Language Assignments ├── C(Array And Function) - Assignment - 15 │ ├── adjanctDuplicateValueInArray.c │ ├── arrayRotateByNandD.c │ ├── countDupliElement.c │ ├── frequencyOfEachElement.c │ ├── greatestNumberFunction.c │ ├── mergeArrayInDecendingOrder.c │ ├── printUniqueElement.c │ ├── reverseArray.c │ ├── smallestNumberFunction.c │ └── sorArrayFunction.c ├── C(Array) - Assignment-14 │ ├── averageOfArray.c │ ├── copyArray.c │ ├── displayReverseArray.c │ ├── evenSum_and_oddSum.c │ ├── greatestNumber.c │ ├── secondLargest.c │ ├── secondSmallestNumber.c │ ├── smallestNumberInArray.c │ ├── sortedArray.c │ └── sumOfArray.c ├── C(Basic String) - Assignment - 17 │ ├── convertLowerCaseString.c │ ├── convertUppercaseString.c │ ├── copyString.c │ ├── countLengthString.c │ ├── countOccurenceGivChar.c │ ├── countVowel.c │ ├── freqOfCharater.c │ ├── reverseString.c │ └── sortString.c ├── C(DMA) - Assignment - 22 │ ├── averageOfDataValues.c │ ├── demostratMemoryLeak.c │ ├── demostrateDanglingPointer.c │ ├── dmaHandleAllocationFailed.c │ ├── inputAndPrintTEXT.c │ ├── largestElement.c │ ├── minAndMaxElementInArray.c │ ├── sumOfAllElement.c │ ├── sumOfNNumUsingMalloc.c │ └── varLengthStrStoreInArrayWithoutWastageMemory.c ├── C(Decision Control Statement)-Assignment-3 │ ├── candidatePassOrFail.c │ ├── divisibleBy5orNot.c │ ├── evenOdd.c │ ├── evenOddWithout%Operator.c │ ├── givenAlfhabetsLowerUpperCase.c │ ├── greaterTwoNumber.c │ ├── greatestAmongThreeNumber.c │ ├── leapYearOrNot.c │ ├── numDivBy3and2.c │ ├── numDivBy7or3.c │ ├── positiveNegativeZero.c │ ├── positiveOrNon-Positive.c │ ├── profitOrLossPercentage.c │ ├── rootsOfGivenQuadraticEq.c │ ├── takeMonthDisplayDays.c │ ├── threeDigitNumberOrNot.c │ ├── uppLowDigSpecial.c │ └── validTriangleOrNot.c ├── C(Function) - Assignment-10 │ ├── N_OddNaturalNum_TSRN.c │ ├── areaOfCircle_TSRS.c │ ├── arragement_TSRS.c │ ├── combination_TSRS.c │ ├── digitOrNot_TSRS.c │ ├── evenOdd_TSRS.c │ ├── factorial_TSRS.c │ ├── primeFacotor_TSRN.c │ ├── printFirstNnaturalnNum.c │ └── simpleIntrest_TSRS.c ├── C(Handling Multiple String) - Assignment-19 │ ├── authenticationSystem.c │ ├── emailAddressContainAt.c │ ├── minWordDistance.c │ ├── numOfVowel.c │ ├── palindromeString.c │ ├── readAndDisplayString.c │ ├── searchString.c │ ├── sortString.c │ └── validIpAddress.c ├── C(Input,Output)-Assignment-1 │ ├── Hello_Students.c │ ├── Hello_Students2.c │ ├── areaOfCircle.c │ ├── findOutput.c │ ├── lengthOfStringUsingPrintf.c │ ├── print-%d-OnScreen.c │ ├── printDOBFormatUsingSlash.c │ ├── printDoubleSlash.c │ ├── printHour&Minute.c │ ├── printMySirgWithDoubleQuotes.c │ ├── printUserNameWithDoubleQuotes.c │ └── printnewline.c ├── C(Loops-For,While,Do-while) - Assignment 7 #4 │ ├── ArmstrongNum.c │ ├── ArmstrongNumUnder100.c │ ├── Co_PrimeNumber.c │ ├── Fibonacci_series.c │ ├── HCF.c │ ├── checkGivenNumFibonacciSeriesBelongorNot.c │ ├── firstNtermFibonacciSeries.c │ ├── nextPrimeNum.c │ ├── printPrimeNumBetGivenRang.c │ └── printPrimeUnder100.c ├── C(Loops-For,While,Do_while) - Assignment-6 #3 │ ├── countDigitOfNumber.c │ ├── factoral.c │ ├── lcmOfTwoNumber.c │ ├── primeOrNot.c │ ├── reverseOfNum.c │ ├── sumOfFirstNNaturalNumCube.c │ ├── sumOfFirstNNumberSquare.c │ ├── sumOfFirstNOddNaturalNum.c │ ├── sumOfFirstNevenNaturalnum.c │ └── sumOfFirstNnaturalNum.c ├── C(Loops-For,Whilte,Do_while) - Assignment-4 #1 │ ├── cubeOfFirst10NaturalNum.c │ ├── first10EvenNaturalNum.c │ ├── first10EvenNaturalNum_ReverseOrder.c │ ├── first10OddNaturalNumReverseOrder.c │ ├── printFirst10NaturalNum.c │ ├── printFirst10NaturalNumIn_ReverseOrder.c │ ├── printMySirg5time.c │ ├── printTableOf_5.c │ ├── printfFirst10OddNaturalNum.c │ └── squareOffirst10NaturalNum.c ├── C(Loops-For,Whilte,Do_while) - Assignment5 #2 │ ├── first_N_NaturalNum_Square.c │ ├── first_N_evenNaturalNum.c │ ├── first_N_evenNum_ReverseOrder.c │ ├── first_N_naturalNum.c │ ├── first_N_naturalNum_Cube.c │ ├── first_N_naturalNum_ReverseOrder.c │ ├── first_N_oddNaturalNum.c │ ├── first_N_oddNaturalNum_ReverseOrder.c │ ├── mysirg_N_times.c │ └── table_of_N.c ├── C(More On Function) - Assignment-11 │ ├── findSquare.c │ ├── findSumOFSeries.c │ ├── firstNPrimeNum_TSRN.c │ ├── hcf_TSRS.c │ ├── lcm_TSRS.c │ ├── nextPrimeNumber_TSRS.c │ ├── pascalTriangle.c │ ├── primeNumber_TSRS.c │ ├── printNFibonacciSeries_TSRN.c │ ├── printPrimeGivenRange_TSRN.c │ └── tempCodeRunnerFile.c ├── C(More On Recursion) - Assignment-13 │ ├── digitCount.c │ ├── factorial.c │ ├── fibonacci_series.c │ ├── hcf.c │ ├── powerOfNumber.c │ ├── sumOfDigit.c │ ├── sumOfEvenNaturalNum.c │ ├── sumOfFirstNnaturalNum.c │ ├── sumOfFirstOddNaturalNum.c │ ├── sumOfSquareNaturalNum.c │ └── tempCodeRunnerFile.c ├── C(Multi-DimestionArray) - Assignment - 16 │ ├── checkSparshMatirx.c │ ├── leftDiagonalsSum.c │ ├── max1WhichRow.c │ ├── printLowerTriangleMatrix.c │ ├── printUpperTriangularMatrix.c │ ├── productOfTwoMatrix.c │ ├── rightDiagonalSum.c │ ├── sumOfMatrix.c │ ├── sumOfTwoMatrix.c │ └── transposeOfMatrix.c ├── C(Operators)-Assignment-2 │ ├── appendDigit.c │ ├── convertUSDtoINR.c │ ├── evenOddUsingBitwise.c │ ├── makeLastDigitOfNumberZero.c │ ├── printASCIICodeOfGivenCharacter.c │ ├── printNumberWithoutLastDigit.c │ ├── printSizeOfDataTypes.c │ ├── sumOfThreeDigitNumber.c │ ├── swapTwoIntegerWithoutThirdVariable.c │ ├── swapTwoValue.c │ ├── take3DigitNumRoateByOne.c │ └── unitDigitOfGivenNumber.c ├── C(Pointers) - Assignment-20 │ ├── handlePointers.c │ ├── lengthOfString.c │ ├── maxNumber.c │ ├── printStringReverse.c │ ├── reverseArrayPrint.c │ ├── sortArray.c │ ├── sumOfArray.c │ ├── swapString.c │ ├── swapValue.c │ ├── tempCodeRunnerFile.c │ └── vowelAndConsonent.c ├── C(Recursion) - Assignment-12 │ ├── EvenNaturalNum.c │ ├── ReverseOrderEven.c │ ├── ReverseOrderNnaturalNum.c │ ├── ReverserOrderNatural.c │ ├── binary_to_octal.c │ ├── decimal_to_binary.c │ ├── n_naturalNum.c │ ├── n_oddNaturalNum.c │ ├── reverse_number.c │ └── square.c ├── C(Star Pattern) Assignment-8 │ ├── starPattern10.c │ ├── starPattern11.c │ ├── starPattern12.c │ ├── starPattern13.c │ ├── starPattern14.c │ ├── starPattern15.c │ ├── starPattern16.c │ ├── starPattern17.c │ ├── starPattern18.c │ ├── starPattern19.c │ ├── starPattern6.c │ ├── startPattern1.c │ ├── startPattern2.c │ ├── startPattern3.c │ ├── startPattern5.c │ ├── startPattern7.c │ ├── startPattern8.c │ └── startPattern9.c ├── C(String and Function) - Assignment-18 │ ├── alphaNumericString.c │ ├── compareString.c │ ├── countWordsInString.c │ ├── lengthOfStringFunnction.c │ ├── lowercaseString.c │ ├── palindromeString.c │ ├── reaptedCharacter.c │ ├── reverseString.c │ ├── reverseStringByWords.c │ ├── tempCodeRunnerFile.c │ └── uppcaseString.c ├── C(Structure) - Assignment-21 │ ├── AverageOfStudents.c │ ├── defineStructure.c │ ├── diffTowTimePeriod.c │ ├── displayEmpyeData.c │ ├── displayStudentInfo.c │ ├── displayStudentInfo2.c │ ├── displayUserData.c │ ├── heightestSalary.c │ └── inputEmployeeData.c └── C(Switch Case Problem) Assignment-9 │ ├── EvenToNearOddNum.c │ ├── convertIf_Else_to_switchCase.c │ ├── convertPosToNegAndNegToPos.c │ ├── findAllRoots.c │ ├── leapYearUsingSwitchCase.c │ ├── menuDrivenProgram.c │ ├── menuDrivenProgram2.c │ ├── takeDaysDisplayMessageForTheDay.c │ ├── takeMonthNumDisplayDays.c │ └── totalElectricityBill.c ├── C++ Language Assignments ├── Basic of C++ - Assignment - 23 │ ├── HelloNewLineMySirG.cpp │ ├── addArrayNum.cpp │ ├── areaOfCircle.cpp │ ├── averageOfThreeNum.cpp │ ├── maxOfTwoNum.cpp │ ├── printHelloMySirG.cpp │ ├── squareOfNumber.cpp │ ├── sumOfTwoNum.cpp │ ├── swapValueWithoutUsingThirdVar.cpp │ └── volumeOfCubiod.cpp ├── C++(Classes and Object) - Assignment - 25 │ ├── Question-01.cpp │ ├── Question-02.cpp │ ├── Question-03.cpp │ ├── Question-04.cpp │ ├── Question-05.cpp │ ├── Question-06.cpp │ ├── Question-07.cpp │ ├── Question-08.cpp │ ├── Question-09.cpp │ └── Question-10.cpp ├── C++(Exception Handling) - Assignment-30 │ ├── Problem1.cpp │ ├── Problem10.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem4.cpp │ ├── Problem5.cpp │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ └── Problem9.cpp ├── C++(File Handling) - Assignment - 34 │ ├── Problem1.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem4.cpp │ ├── Problem5.cpp │ └── Problem6.cpp ├── C++(Functions) - Assignment - 24 │ ├── addTwoNumFunctionOverloading.cpp │ ├── areaFunctionOverloading.cpp │ ├── checkFibonacciSeriesNum.cpp │ ├── defaultArgumentFunction.cpp │ ├── heighestValueDigit.cpp │ ├── maxNumFunctionOverLoading.cpp │ ├── pascalTriangle.cpp │ ├── power.cpp │ ├── primeNumOrNot.cpp │ └── swapDataUsingCallByReference.cpp ├── C++(Member Function, Static and Constructor) - Assignment-26 │ ├── Question-01.cpp │ ├── Question-02.cpp │ ├── Question-03.cpp │ ├── Question-05.cpp │ ├── Question-06.cpp │ ├── Question-07.cpp │ ├── Question-08.cpp │ ├── Question-09.cpp │ └── Question-10.cpp ├── C++(New, Delete and Inheritance) - Assignment - 31 │ ├── Problem1.cpp │ ├── Problem10.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem4.cpp │ ├── Problem5.cpp │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ └── Problem9.cpp ├── C++(Operator overloading and friend function) - Assignment - 27 │ ├── Question-01.cpp │ ├── Question-02.cpp │ ├── Question-03.cpp │ ├── Question-04.cpp │ ├── Question-05.cpp │ ├── Question-06.cpp │ ├── Question-07.cpp │ ├── Question-08.cpp │ ├── Question-09.cpp │ └── Question-10.cpp ├── C++(Operator overloading, Friend function and this pointer) - Assignment-28 │ ├── Problem1.cpp │ ├── Problem10.cpp │ ├── Problem11.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ └── Problem9.cpp ├── C++(Overriding, Overloading, Constructor in Inheritance) - Assignment - 32 │ ├── Problem1.cpp │ ├── Problem10.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem4.cpp │ ├── Problem5.cpp │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ └── Problem9.cpp ├── C++(Templates) - Assignment - 35 │ ├── Problem1.cpp │ ├── Problem10.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem4.cpp │ ├── Problem5.cpp │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ └── Problem9.cpp ├── C++(Typecasting and Conversion) - Assignment-29 │ ├── Problem1.cpp │ ├── Problem10.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem4.cpp │ ├── Problem5.cpp │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ └── Problem9.cpp └── C++(Virtual Function, Abstract Class) - Assignment - 33 │ ├── Problem1.cpp │ ├── Problem2.cpp │ ├── Problem3.cpp │ ├── Problem4.cpp │ ├── Problem5.cpp │ ├── Problem6.cpp │ ├── Problem7.cpp │ ├── Problem8.cpp │ └── Problem9.cpp ├── Competitive Programming ├── Problem-1-Pallindrome_Integer.cpp ├── Problem-2-productOfArrayExceptSelf.cpp ├── Problem-3-peakIndexInAMountainArray.cpp └── Problem-4-MedianOfTwoSortedArray.cpp ├── Projects ├── C Languages Projects │ ├── C Library On Analytic Geometry │ │ ├── Analytic_Geometry.c │ │ ├── Analytic_Geometry.h │ │ ├── Problem1.c │ │ ├── Problem2.c │ │ └── Problem3.c │ ├── Number_Shifting_Game │ │ └── Number_Shifting_Game.c │ ├── Number_Shifting_Game_2.0 │ │ └── NumberShiftingGame2.0.c │ └── tic_tac_toe.c └── C++ Languages Projects │ ├── C++ program to detect tokens │ └── detectToken.cpp │ ├── Student Record using File Handling │ ├── main.exe │ ├── studentData.cpp │ ├── studentData.exe │ ├── studentData.txt │ └── studentId.txt │ └── Tic-Tac-Toe Game │ ├── TIC-TAC-TOE GAME VIDEO.mp4 │ ├── tic_tac_toe.c │ ├── tic_tac_toe_game.cpp │ └── tic_tac_toe_game_with_newFeature.cpp └── README.md /All Assignments Questions Links/Assignment-01.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1rYENIYrdEEfLCQX84q7GHliwdaa7I62A/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-02.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/197OLr8AmiWFMyfpynVY3KhBNCuzI8tKo/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-03.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1I2tMyjbaAQVBk7ZMYrd5vgl9P_L3fLi7/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-04.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/19QhVkcYi5BiGtsCUExwFaWS6lP2ljdvo/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-05.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1DoOrETieSgbH2PNRn89NT4esgUftrmrv/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-06.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1WLazFENUt7FK9YaOjd9Twdv1O16CY9ds/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-07.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1pBHX0MBF6ZTfXKtLpVOlBMNFsaGCMKVA/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-08.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1CvndH6RYpz5V6OGQvZcoXpp6No_HEqiM/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-09.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1alsQ8-9wgwgryCW-jUGyNgDBYL9em4VH/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-10.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1GuBtpn2Mg0L-AFs9puVwUyz8424VM1iw/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-11.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1Me-owBhOFfyauR_uHB-MnKgcMK9K8CPa/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-12.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1sVqaax-C_-Ty6LUEUpfvS_snsifJ_31Q/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-13.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/12B4yvbYQtMzG7d0zwjntBUt2s9zjs8QG/views -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-14.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/18cnCYUXHeW_m6NcLgTSAo5v5TVdAgL05/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-15.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1rzNaC6xbCrY2TZDOR39mblWrl0031qqS/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-16.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/12fNhKEKPy2iK1L-XXC1TMLHSf6ZPoMVm/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-17.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1_YL-jpRabZoNdwy8kvXOnHRfZPg5Z1f4/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-18.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1-dsePZ4kb87uECIdwsoGbwaOOwDPaan3/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-19.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1x3MsAf00quIaLHRbwjy8-2VUaEOFuneY/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-20.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1F1yLbB6hdhShdmxe14GGbrGNo76lg6-c/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-21.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1NlnsDMYfGl8CDAxZK-aBVrB15I-0Z4it/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-22.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1Gj_Fee0xpDc4oFCqI97Er0r1tvafR5ng/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-23.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1c5eovW4XmN0nWK0V09uj7s8AZEoOlHY4/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-24.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/1BJwW2l7neW-yiA0HRdAMPxtal9JYO3Ts/view -------------------------------------------------------------------------------- /All Assignments Questions Links/Assignment-25.txt: -------------------------------------------------------------------------------- 1 | https://drive.google.com/file/d/12_gRXfWMVoMzoWWcqBlSaW-KHaxf19YB/view -------------------------------------------------------------------------------- /C Language Assignments/C(Array And Function) - Assignment - 15/adjanctDuplicateValueInArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int firstDValue(int arr[],int arrSize) 3 | { 4 | for(int i=1; i 2 | 3 | int greatestNum(int a[], int n) 4 | { 5 | int gNum = a[0]; 6 | for(int i = 1; i 2 | 3 | void printUniqueElement(int arr[],int arrSize) 4 | { 5 | int i,j,flag; 6 | for(i=0; i 2 | 3 | void reverseArary(int arr[], int arrSize) 4 | { 5 | printf("\nReverse Order Array Display: "); 6 | for(int i=arrSize-1; i>=0; i--) 7 | printf("%d ",arr[i]); 8 | } 9 | 10 | int main() 11 | { 12 | int arrSize; 13 | printf("How many number you want to enter: "); 14 | scanf("%d",&arrSize); 15 | 16 | int arr[arrSize]; 17 | 18 | printf("Enter %d Number: ",arrSize); 19 | for(int i=0; i 2 | 3 | int greatestNum(int a[], int n) 4 | { 5 | int sNum = a[0]; 6 | for(int i = 1; i a[i]) 9 | sNum = a[i]; 10 | } 11 | return sNum; 12 | } 13 | 14 | int main() 15 | { 16 | int size,sNumber; 17 | printf("Enter Array size: "); 18 | scanf("%d",&size); 19 | 20 | int arr[size]; 21 | printf("Enter %d Element in Array: \n",size); 22 | for(int i=0; i 2 | 3 | void sortArray(int a[], int n) 4 | { 5 | for(int i = 0; ia[j]) 10 | { 11 | int temp = a[j]; 12 | a[j] = a[i]; 13 | a[i] = temp; 14 | } 15 | } 16 | } 17 | } 18 | 19 | int main() 20 | { 21 | int size; 22 | printf("Enter Array size: "); 23 | scanf("%d",&size); 24 | 25 | int arr[size]; 26 | 27 | printf("Enter %d Element in Array: \n",size); 28 | for(int i=0; i 2 | int main() 3 | { 4 | int arr[10],sum=0; 5 | printf("Enter 10 number: \n"); 6 | for(int i=0; i<=9; i++) 7 | { 8 | printf("Enter %d number: ",i+1); 9 | scanf("%d",&arr[i]); 10 | sum = sum + arr[i]; 11 | } 12 | printf("\nAverage all Element in Array is: %.2f",sum/10.0f); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/copyArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many number u want to enter: "); 6 | scanf("%d", &n); 7 | 8 | int firstArray[n], secondArray[n]; 9 | 10 | printf("Enter %d number in firstArray: \n", n); 11 | for (int i = 0; i < n; i++) 12 | { 13 | printf("Enter %d number: ", i + 1); 14 | scanf("%d", &firstArray[i]); 15 | } 16 | 17 | printf("\nBefore copy element second array contain garbage value: "); 18 | for (int i = 0; i < n; i++) 19 | printf("%d ", secondArray[i]); 20 | 21 | for (int i = 0; i < n; i++) 22 | { 23 | secondArray[i] = firstArray[i]; 24 | } 25 | 26 | printf("\nAfter copy element second array will be: "); 27 | for (int i = 0; i < n; i++) 28 | printf("%d ", secondArray[i]); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/displayReverseArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many number u want to enter: "); 6 | scanf("%d",&n); 7 | 8 | int arr[n]; 9 | 10 | printf("Enter %d number: \n",n); 11 | for(int i=0; i=0; i--) 23 | printf("%d ",arr[i]); 24 | 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/evenSum_and_oddSum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[10],evenSum=0,oddSum=0; 5 | printf("Enter 10 number: \n"); 6 | for(int i=0; i<=9; i++) 7 | { 8 | printf("Enter %d number: ",i+1); 9 | scanf("%d",&arr[i]); 10 | if(arr[i]%2==0) 11 | evenSum+=arr[i]; 12 | else 13 | oddSum+=arr[i]; 14 | } 15 | printf("\nEven sum of All even element present in array: %d",evenSum); 16 | printf("\nOdd sum of All odd element present in array: %d",oddSum); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/greatestNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[10],gSum; 5 | printf("Enter 10 number: \n"); 6 | for(int i=0; i<=9; i++) 7 | { 8 | printf("Enter %d number: ",i+1); 9 | scanf("%d",&arr[i]); 10 | } 11 | gSum = arr[0]; 12 | for(int i=1; i<=9; i++) 13 | { 14 | if(gSum 2 | int main() 3 | { 4 | int size; 5 | printf("How many number u want to enter: "); 6 | scanf("%d",&size); 7 | 8 | int arr[size]; 9 | 10 | printf("Enter %d number: \n",size); 11 | for(int i=0; iarr[j]) 22 | { 23 | int temp = arr[i]; 24 | arr[i] = arr[j]; 25 | arr[j] = temp; 26 | } 27 | } 28 | } 29 | 30 | printf("\nSecond largest element is: %d",arr[size-2]); 31 | 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/secondSmallestNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int size; 5 | printf("How many number u want to enter: "); 6 | scanf("%d",&size); 7 | 8 | int arr[size]; 9 | 10 | printf("Enter %d number: \n",size); 11 | for(int i=0; iarr[j]) 22 | { 23 | int temp = arr[i]; 24 | arr[i] = arr[j]; 25 | arr[j] = temp; 26 | } 27 | } 28 | } 29 | 30 | printf("\nSecond smallest element is: %d",arr[1]); 31 | 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/smallestNumberInArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[10],gSum; 5 | printf("Enter 10 number: \n"); 6 | for(int i=0; i<=9; i++) 7 | { 8 | printf("Enter %d number: ",i+1); 9 | scanf("%d",&arr[i]); 10 | } 11 | gSum = arr[0]; 12 | for(int i=1; i<=9; i++) 13 | { 14 | if(gSum>arr[i]) 15 | gSum = arr[i]; 16 | } 17 | printf("\nSmallest number in Array is: %d",gSum); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/sortedArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[10],gSum; 5 | printf("Enter 10 number: \n"); 6 | for(int i=0; i<=9; i++) 7 | { 8 | printf("Enter %d number: ",i+1); 9 | scanf("%d",&arr[i]); 10 | } 11 | 12 | printf("\nBeforeḥ sorted array: "); 13 | for(int i=0; i<=9; i++) 14 | printf("%d ",arr[i]); 15 | 16 | for(int i=0; i<=9; i++) 17 | { 18 | for(int j=i+1; j<=9; j++) 19 | { 20 | if(arr[i]>arr[j]) 21 | { 22 | int temp = arr[i]; 23 | arr[i] = arr[j]; 24 | arr[j] = temp; 25 | } 26 | } 27 | } 28 | 29 | printf("\nAfter sorted array: "); 30 | for(int i=0; i<=9; i++) 31 | printf("%d ",arr[i]); 32 | 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /C Language Assignments/C(Array) - Assignment-14/sumOfArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int arr[10],sum=0; 5 | printf("Enter 10 number: \n"); 6 | for(int i=0; i<=9; i++) 7 | { 8 | printf("Enter %d number: ",i+1); 9 | scanf("%d",&arr[i]); 10 | sum = sum + arr[i]; 11 | } 12 | printf("\nSum of All arrays number: %d",sum); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/convertLowerCaseString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | char str[100]; 6 | printf("Enter String: "); 7 | fgets(str, 100, stdin); 8 | 9 | for (int i = 0; str[i]; i++) 10 | if (str[i] >= 'A' && str[i] <= 'Z') 11 | str[i] = str[i] + 32; 12 | 13 | printf("Convert string in lowercase: %s", str); 14 | /* 15 | using Build-in Method 16 | printf("Convert string in uppercase: %s",strlwr(str)); 17 | */ 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/convertUppercaseString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | char str[100]; 6 | printf("Enter String: "); 7 | fgets(str, 100, stdin); 8 | 9 | for (int i = 0; str[i]; i++) 10 | if (str[i] >= 'a' && str[i] <= 'z') 11 | str[i] = str[i] - 32; 12 | 13 | printf("Convert string in uppercase: %s", str); 14 | 15 | /* 16 | using Build-in Method 17 | printf("Convert string in uppercase: %s",strupr(str)); 18 | */ 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/copyString.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[100], copyString[100]; 5 | printf("Enter string: "); 6 | fgets(str, 100, stdin); 7 | 8 | for (int i = 0; str[i]; i++) 9 | copyString[i] = str[i]; 10 | 11 | printf("\nCopy string: %s", copyString); 12 | 13 | /* 14 | strcpy(copyArray,str); 15 | */ 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/countLengthString.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[] = "Ajay Soni"; 5 | int i; 6 | // Count Length of String 7 | for(i=0; str[i]; i++); 8 | printf("\nLength of String: %d",i); 9 | 10 | // We Use Built-in method - strlen(); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/countOccurenceGivChar.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[] = "Ajay Soni"; 5 | char ch; 6 | int countOcc = 0; 7 | printf("Enter Character: - "); 8 | scanf("%c", &ch); 9 | for (int i = 0; str[i]; i++) 10 | if (str[i] == ch) 11 | countOcc++; 12 | printf("\nOccurence of '%c' Character in \"%s\" string is: %d", ch, str, countOcc); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/countVowel.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[100]; 5 | int countVowel = 0; 6 | printf("Enter String: "); 7 | fgets(str, 100, stdin); 8 | 9 | for (int i = 0; str[i]; i++) 10 | if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U') 11 | countVowel++; 12 | 13 | printf("\nGiven string total vowel is: %d", countVowel); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/freqOfCharater.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[100]; 5 | printf("Enter String: "); 6 | fgets(str, 100, stdin); 7 | 8 | // sort 9 | for (int i = 0; str[i]; i++) 10 | { 11 | for (int j = 0; str[j]; j++) 12 | { 13 | if (str[i] < str[j]) 14 | { 15 | int temp = str[i]; 16 | str[i] = str[j]; 17 | str[j] = temp; 18 | } 19 | } 20 | } 21 | // Count Freq 22 | int count, i = 0, j; 23 | while (str[i]) 24 | { 25 | count = 0; 26 | for (j = i; str[j]; j++) 27 | { 28 | if (str[i] == str[j]) 29 | count++; 30 | else 31 | break; 32 | } 33 | printf("\n%c Character Frequency is: %d", str[i], count); 34 | i = j; 35 | } 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/reverseString.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[100]; 5 | printf("Enter String: "); 6 | fgets(str, 100, stdin); 7 | 8 | int alphabets = 0, digit = 0, specialCharacter = 0; 9 | for (int i = 0; str[i]; i++) 10 | { 11 | if (str[i] >= '0' && str[i] <= '9') 12 | digit++; 13 | else if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) 14 | alphabets++; 15 | else 16 | specialCharacter++; 17 | } 18 | 19 | printf("\nTotal no. of Digit is %d\nTotal no. of Alphabets is: %d\nTotal no. of Special Character(consider null character) is: %d", digit, alphabets, specialCharacter); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Basic String) - Assignment - 17/sortString.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[100]; 5 | printf("Enter String: "); 6 | fgets(str, 100, stdin); 7 | 8 | // sort 9 | for (int i = 0; str[i]; i++) 10 | { 11 | for (int j = 0; str[j]; j++) 12 | { 13 | if (str[i] < str[j]) 14 | { 15 | int temp = str[i]; 16 | str[i] = str[j]; 17 | str[j] = temp; 18 | } 19 | } 20 | } 21 | 22 | printf("Sorted String: %s",str); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/averageOfDataValues.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int countOfData, sumOfValues = 0; 6 | float averageOfValues; 7 | printf("input a number of data values you would like to enter: "); 8 | scanf("%d", &countOfData); 9 | int *ptr; 10 | // ptr = (int *)calloc(countOfData, sizeof(int)); 11 | ptr = (int *)malloc(sizeof(int) * countOfData); 12 | for (int i = 0; i < countOfData; i++) 13 | { 14 | printf("Enter %d value: ", i + 1); 15 | scanf("%d", (ptr + i)); 16 | sumOfValues += *(ptr + i); 17 | } 18 | 19 | averageOfValues = sumOfValues / (float)countOfData; 20 | printf("Average of data values: %.2f", averageOfValues); 21 | free(ptr); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/demostratMemoryLeak.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void memoryLeak() 4 | { 5 | int *ptr = (int *)malloc(sizeof(int)); // ptr contain address of 4 bytes memory 6 | // here we performs operator in ptr 7 | // but we don't realise ptr contain memory so it's called memory leak because after functione end ptr will be destroy so dma memory is avaiable but we don't access becuase we don't havae address of dma memory 8 | // here we use free(address) function or we return address 9 | } 10 | int main() 11 | { 12 | 13 | memoryLeak(); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/demostrateDanglingPointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int *ptr; 4 | { 5 | int x = 5; 6 | ptr = &x; 7 | } 8 | // now ptr become dangling pointer becusae ptr contains address of x but x is destroy but ptr contain x address 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/dmaHandleAllocationFailed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int bytes; 6 | printf("Enter size in bytes for allocating memory dymanically: "); 7 | scanf("%d", &bytes); 8 | int *ptr = NULL; 9 | ptr = (int *)malloc(bytes); 10 | if (ptr != NULL) 11 | printf("Memory Allocated Successfull!"); 12 | else 13 | printf("Memory Error!"); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/inputAndPrintTEXT.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char *inputTEXT() 4 | { 5 | int txtLength; 6 | printf("input length of text: "); 7 | scanf("%d", &txtLength); 8 | fflush(stdin); 9 | char *ptr = (char *)malloc(sizeof(char) * txtLength); 10 | printf("Input Text: "); 11 | fgets(ptr, txtLength * sizeof(char), stdin); 12 | return ptr; 13 | } 14 | void outputText(char *ptr) 15 | { 16 | printf("Output Text: %s", ptr); 17 | } 18 | int main() 19 | { 20 | char *ptr; 21 | ptr = inputTEXT(); 22 | outputText(ptr); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/largestElement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int *inputElement(int n) 4 | { 5 | printf("Input %d Element: ", n); 6 | int *ptr = (int *)malloc(sizeof(int) * n); 7 | for (int i = 0; i < n; i++) 8 | { 9 | printf("Enter %d Element: ", i + 1); 10 | scanf("%d", (ptr + i)); 11 | } 12 | return ptr; 13 | } 14 | int largestElement(int *ptr, int n) 15 | { 16 | int largestElement = -1; 17 | for (int i = 0; i < n; i++) 18 | { 19 | if (largestElement < *(ptr + i)) 20 | { 21 | largestElement = *(ptr + i); 22 | } 23 | } 24 | return largestElement; 25 | } 26 | int main() 27 | { 28 | int n; 29 | printf("How many element u want to enter: "); 30 | scanf("%d", &n); 31 | int *ptr; 32 | ptr = inputElement(n); 33 | int large = largestElement(ptr, n); 34 | printf("%d is largest Element", large); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/minAndMaxElementInArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int *inputElement(int n) 4 | { 5 | printf("Input %d Element: ", n); 6 | int *ptr = (int *)malloc(sizeof(int) * n); 7 | for (int i = 0; i < n; i++) 8 | { 9 | printf("Enter %d Element: ", i + 1); 10 | scanf("%d", (ptr + i)); 11 | } 12 | return ptr; 13 | } 14 | int minAndMaxElement(int *ptr, int n) 15 | { 16 | int max = -1; 17 | int min = __INT_MAX__; 18 | for (int i = 0; i < n; i++) 19 | { 20 | if (max < *(ptr + i)) 21 | max = *(ptr + i); 22 | 23 | if (min > *(ptr + i)) 24 | min = *(ptr + i); 25 | } 26 | printf("Min Element - %d, Max Element - %d", min, max); 27 | } 28 | int main() 29 | { 30 | int n; 31 | printf("How many element u want to enter: "); 32 | scanf("%d", &n); 33 | int *ptr; 34 | ptr = inputElement(n); 35 | minAndMaxElement(ptr, n); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/sumOfAllElement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int n, sum = 0; 6 | printf("How many element u want to enter: "); 7 | scanf("%d", &n); 8 | int *ptr = (int *)malloc(sizeof(int) * n); 9 | printf("Input %d Element: ", n); 10 | for (int i = 0; i < n; i++) 11 | { 12 | printf("\nEnter %d Element: ", i + 1); 13 | scanf("%d", (ptr + i)); 14 | sum += *(ptr + i); 15 | } 16 | printf("\nsum is %d", sum); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/sumOfNNumUsingMalloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int sumOfNValues(int n) 4 | { 5 | int sum = 0; 6 | int *ptr = (int *)malloc(sizeof(int) * n); 7 | for (int i = 0; i < n; i++) 8 | { 9 | printf("Enter %d Values: ", i + 1); 10 | scanf("%d", (ptr + i)); 11 | sum += *(ptr + i); 12 | } 13 | free(ptr); // relise dma memory 14 | return sum; 15 | } 16 | int main() 17 | { 18 | int n; 19 | printf("How many values you want to enter: "); 20 | scanf("%d", &n); 21 | int sum = sumOfNValues(n); 22 | printf("\nSum of %d Values is: %d", n, sum); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C Language Assignments/C(DMA) - Assignment - 22/varLengthStrStoreInArrayWithoutWastageMemory.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char* inputVarLengthString() 4 | { 5 | int varLength; 6 | printf("Enter variable length: "); 7 | scanf("%d", &varLength); 8 | char *ptr = (char *)calloc(varLength, sizeof(char)); 9 | printf("Input %d length string: ", varLength); 10 | fflush(stdin); 11 | fgets(ptr, varLength * sizeof(char) + 1, stdin); // +1 because 1 character hold null character 12 | return ptr; 13 | } 14 | int main() 15 | { 16 | char *ptr; 17 | ptr = inputVarLengthString(); 18 | printf("You enter string - %s", ptr); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/candidatePassOrFail.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int sub1, sub2, sub3, sub4, sub5; 5 | printf("Enter 5 subjects marks out of 100: "); 6 | scanf("%d%d%d%d%d", &sub1, &sub2, &sub3, &sub4, &sub5); 7 | if (sub1 >= 33 && sub2 >= 33 && sub3 >= 33 && sub4 >= 33 && sub5 >= 33) 8 | printf("Candidate is Passed!"); 9 | else 10 | printf("Candidate is Failed!"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/divisibleBy5orNot.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | if(num%5==0) 8 | printf("It is divisible by 5"); 9 | else 10 | printf("Not divisible by 5"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/evenOdd.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | if(num%2==0) 8 | printf("Even number"); 9 | else 10 | printf("Odd number"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/evenOddWithout%Operator.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | if(num&1==1) 8 | printf("Odd number"); 9 | else 10 | printf("Even number"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/givenAlfhabetsLowerUpperCase.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char ch; 5 | printf("Enter any alfhabet: "); 6 | scanf("%c", &ch); 7 | if (ch >= 'A' && ch <= 'Z') 8 | printf("UpperCase!"); 9 | else 10 | printf("LowerCase!"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/greaterTwoNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num1, num2; 5 | printf("Enter a two number: "); 6 | scanf("%d%d", &num1, &num2); 7 | if (num1 == num2) 8 | printf("Both number are same, Number - %d", num1); 9 | else if (num1 > num2) 10 | printf("%d is greater than %d", num1,num2); 11 | else 12 | printf("%d is greater than %d", num2,num1); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/greatestAmongThreeNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a, b, c; 5 | printf("Enter a three number: "); 6 | scanf("%d%d%d", &a, &b, &c); 7 | if (a > b && a > c) 8 | printf("Gretest number is: %d", a); 9 | else if (b > c) 10 | printf("Gretest number is: %d", b); 11 | else 12 | printf("Gretest number is: %d", c); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/leapYearOrNot.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int year; 5 | printf("Enter a year: "); 6 | scanf("%d", &year); 7 | if (year % 400 == 0) 8 | printf("Leap year"); 9 | else if (year % 100 == 0) 10 | printf("Not a leap year"); 11 | else if (year % 4 == 0) 12 | printf("Leap year"); 13 | else 14 | printf("Not leap year"); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/numDivBy3and2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d",&num); 7 | if(num%3==0 && num%2==0) 8 | printf("Divisble!"); 9 | else 10 | printf("Not divisible1"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/numDivBy7or3.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d",&num); 7 | if(num%3==0 || num%7==0) 8 | printf("Divisble!"); 9 | else 10 | printf("Not divisible1"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/positiveNegativeZero.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d",&num); 7 | if(num>0) 8 | printf("Positive"); 9 | else if(num<0) 10 | printf("Negative"); 11 | else 12 | printf("Zero"); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/positiveOrNon-Positive.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | if (num > 0) 8 | printf("Positive"); 9 | else 10 | printf("Non-Positive"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/profitOrLossPercentage.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int cp, sp; 5 | printf("Enter a cost price and selling price of product: "); 6 | scanf("%d%d", &cp, &sp); 7 | int amountAfterSelling = sp - cp; 8 | if (amountAfterSelling == 0) 9 | printf("No Profit or No Loss, Profit or loss % wil be 0%"); 10 | else if (amountAfterSelling > 0) 11 | printf("Profit, Profit percentage is: %f", (amountAfterSelling * 100.0) / cp); 12 | else 13 | printf("Loss, loss percentage is: %f", (abs(amountAfterSelling) * 100.0) / cp); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/rootsOfGivenQuadraticEq.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | // D = b^2 - 4*a*c 5 | int a, b, c; 6 | printf("Enter quadratic equation cofficent symultanously: "); 7 | scanf("%d%d%d", &a, &b, &c); 8 | int d = (b * b) - (4 * a * c); 9 | if (d > 0) 10 | printf("Roots are real and distinct"); 11 | else if (d == 0) 12 | printf("Roots are real and equal"); 13 | else 14 | printf("Roots are imaginary"); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/takeMonthDisplayDays.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | // 31 - jan, march, may, july,Aug,oct,dec 5 | int month; 6 | printf("Enter month number: "); 7 | scanf("%d", &month); 8 | if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 9 || month == 11) 9 | printf("31 Days!"); 10 | else if (month == 2) 11 | printf("28 or 29 days depond on leap year!"); 12 | else 13 | printf("30 days"); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/threeDigitNumberOrNot.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | if (num > 99 && num < 1000) 8 | printf("Yes, Three digit number"); 9 | else 10 | printf("Not,Three digit number"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/uppLowDigSpecial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char ch; 5 | printf("Ente a character: "); 6 | scanf("%c",&ch); 7 | if(ch>='A' && ch<='Z') 8 | printf("%c - Alfhabets(UpperCase)",ch); 9 | else if(ch>='a' && ch<='z') 10 | printf("%c - Alfhabet(LowerCase)",ch); 11 | else if(ch>='0' && ch<='9') 12 | printf("%c - Digit",ch); 13 | else 14 | printf("%c - Special Character",ch); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C Language Assignments/C(Decision Control Statement)-Assignment-3/validTriangleOrNot.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a, b, c; 5 | printf("Enter a sides of trinagle: "); 6 | scanf("%d%d%d", &a, &b, &c); 7 | if (b + c > a && a + c > b && a + b > c) 8 | printf("Triagnle is valid!"); 9 | else 10 | printf("Triangel is not valid!"); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/N_OddNaturalNum_TSRN.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | for (int i = 1; i <= n*2; i+=2) 5 | printf("%d ", i); 6 | } 7 | int main() 8 | { 9 | int n; 10 | printf("Enter the number: "); 11 | scanf("%d",&n); 12 | print(n); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/areaOfCircle_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | float findArea(int r) 3 | { 4 | return 3.14*r*r; 5 | } 6 | int main() 7 | { 8 | int radius; 9 | printf("Enter the radius of circle: "); 10 | scanf("%d",&radius); 11 | printf("Area of circle is: %.2f",findArea(radius)); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/arragement_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fact(int n) 3 | { 4 | int fact=1; 5 | for(int i=1; i<=n; i++) 6 | fact*=i; 7 | return fact; 8 | } 9 | int arrange(int n,int r) 10 | { 11 | return fact(n)/fact(n-r); 12 | } 13 | int main() 14 | { 15 | int x,y; 16 | printf("Enter the two number: "); 17 | scanf("%d%d", &x,&y); 18 | printf("%d arrangement!",arrange(x,y)); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/combination_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fact(int n) 3 | { 4 | int fact=1; 5 | for(int i=1; i<=n; i++) 6 | fact*=i; 7 | return fact; 8 | } 9 | int combi(int n,int r) 10 | { 11 | return fact(n)/(fact(n-r)*fact(r)); 12 | } 13 | int main() 14 | { 15 | int x,y; 16 | printf("Enter the two number: "); 17 | scanf("%d%d", &x,&y); 18 | printf("%d combination!",combi(x,y)); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/digitOrNot_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | int check(int n, int digit) 3 | { 4 | while (n != 0) 5 | { 6 | if (n % 10 == digit) 7 | return 1; 8 | n /= 10; 9 | } 10 | return 0; 11 | } 12 | int main() 13 | { 14 | int num, digit; 15 | printf("Enter the two number: "); 16 | scanf("%d%d", &num, &digit); 17 | if (check(num, digit)) 18 | printf("YEs! contain"); 19 | else 20 | printf("Not! Contain"); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/evenOdd_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | int checkEvenOdd(int n) 3 | { 4 | if (n % 2 == 0) 5 | return 1; 6 | return 0; 7 | } 8 | int main() 9 | { 10 | int num; 11 | printf("Enter the number: "); 12 | scanf("%d", &num); 13 | if (checkEvenOdd(num)) 14 | printf("Number is even"); 15 | else 16 | printf("Number is odd"); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/factorial_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fact(int n) 3 | { 4 | int fact=1; 5 | for(int i=1; i<=n; i++) 6 | fact*=i; 7 | return fact; 8 | } 9 | int main() 10 | { 11 | int num; 12 | printf("Enter the number: "); 13 | scanf("%d", &num); 14 | printf("Factorial is: %d",fact(num)); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/primeFacotor_TSRN.c: -------------------------------------------------------------------------------- 1 | #include 2 | int primeFactor(int n) 3 | { 4 | int i,j; 5 | for (i = 1; i <= n; i++) 6 | { 7 | if (n % i == 0) 8 | { 9 | for (j = 2; j <= i / 2; j ++) 10 | { 11 | if (i % j == 0) 12 | break; 13 | } 14 | if (j - 1 == i / 2) 15 | printf("%d ", i); 16 | } 17 | } 18 | } 19 | int main() 20 | { 21 | int num; 22 | printf("Enter the number: "); 23 | scanf("%d", &num); 24 | primeFactor(num); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/printFirstNnaturalnNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | for (int i = 1; i <= n; i++) 5 | printf("%d ", i); 6 | } 7 | int main() 8 | { 9 | int n; 10 | printf("Enter the number: "); 11 | scanf("%d",&n); 12 | print(n); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Function) - Assignment-10/simpleIntrest_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | float simpleIntrest(float p, float r, float t) 3 | { 4 | return (p * r * t) / 100.0; 5 | } 6 | int main() 7 | { 8 | float p, r, t; 9 | printf("Enter the value of P,R,T: "); 10 | scanf("%f%f%f", &p, &r, &t); 11 | printf("Simple Intrest is: %.2f", simpleIntrest(p, r, t)); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Handling Multiple String) - Assignment-19/authenticationSystem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int flag = 0, i; 6 | char a[3][2][20] = { 7 | {"Ajay", "123"}, 8 | {"Soni", "456"}, 9 | {"Silent", "123"}}; 10 | 11 | char userName[] = "Silent"; 12 | char passWord[] = "456"; 13 | 14 | for (i = 0; i < 3; i++) 15 | { 16 | if (strcmp(userName, a[i][0]) == 0 && strcmp(passWord, a[i][1])==0) 17 | { 18 | flag = 1; 19 | break; 20 | } 21 | } 22 | if (flag == 0) 23 | printf("Username or Password doesn't match!"); 24 | else 25 | printf("Login Successfull!"); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Handling Multiple String) - Assignment-19/emailAddressContainAt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int noOfString; 6 | printf("How many string u want to enter: "); 7 | scanf("%d", &noOfString); 8 | printf("Enter %d String: ", noOfString); 9 | fflush(stdin); // for clear buffer 10 | char str[noOfString][100]; 11 | for (int i = 0; i < noOfString; i++) 12 | fgets(str[i], 100, stdin); 13 | 14 | printf("\nnot @ contain Email\n\n"); 15 | for (int i = 0; i < noOfString; i++) 16 | { 17 | int flag = 0; 18 | for (int j = 0; str[i][j]; j++) 19 | { 20 | if (str[i][j] == '@') 21 | { 22 | flag = 1; 23 | break; 24 | } 25 | } 26 | if (flag == 0) 27 | printf("%s", str[i]); 28 | ; 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Handling Multiple String) - Assignment-19/minWordDistance.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | char words[5][20] = {"My", "Name", "Is", "Ajay", "Soni"}; 6 | char word1[] = "My"; 7 | char word2[] = "Ajay"; 8 | int i, indWord1 = -1, indWord2 = -1, min = 100000; 9 | for (i = 0; i < 5; i++) 10 | { 11 | if (strcmp(words[i], word1) == 0) 12 | indWord1 = i; 13 | if (strcmp(words[i], word2) == 0) 14 | indWord2 = i; 15 | if (indWord1 != -1 && indWord2 != -1) 16 | min = abs(indWord1 - indWord2); 17 | } 18 | printf("Minimum distance of two words is: %d", min-1); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Handling Multiple String) - Assignment-19/numOfVowel.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char str[5][100]; 5 | for (int i = 0; i < 5; i++) 6 | fgets(str[i], 100, stdin); 7 | 8 | int count; 9 | for (int i = 0; i < 5; i++) 10 | { 11 | count = 0; 12 | for (int j = 0; str[i][j]; j++) 13 | { 14 | if (str[i][j] == 'a' || str[i][j] == 'e' || str[i][j] == 'i' || str[i][j] == 'o' || str[i][j] == 'u' || str[i][j] == 'A' || str[i][j] == 'E' || str[i][j] == 'I' || str[i][j] == 'O' || str[i][j] == 'U') 15 | count++; 16 | } 17 | printf("\n%d String contan %d Vowel", i + 1, count); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Handling Multiple String) - Assignment-19/readAndDisplayString.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int noOfString; 6 | printf("How many string u want to enter: "); 7 | scanf("%d", &noOfString); 8 | printf("Enter %d String: ", noOfString); 9 | fflush(stdin); // for clear buffer 10 | char str[noOfString][100]; 11 | for (int i = 0; i < noOfString; i++) 12 | fgets(str[i], 100, stdin); 13 | 14 | printf("Strings: \n"); 15 | for (int i = 0; i < noOfString; i++) 16 | { 17 | printf("%d String - %s", i + 1, str[i]); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Handling Multiple String) - Assignment-19/searchString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int noOfString; 6 | printf("How many string u want to enter: "); 7 | scanf("%d", &noOfString); 8 | printf("Enter %d String: ", noOfString); 9 | fflush(stdin); // for clear buffer 10 | char str[noOfString][100]; 11 | for (int i = 0; i < noOfString; i++) 12 | fgets(str[i], 100, stdin); 13 | 14 | char search[100]; 15 | printf("\nEnter Search string: "); 16 | fgets(search, 100, stdin); 17 | 18 | int flag = 0; 19 | for (int i = 0; i < noOfString; i++) 20 | { 21 | if (strcmp(str[i], search) == 0) 22 | { 23 | flag = 1; 24 | break; 25 | } 26 | } 27 | if (flag) 28 | printf("Yes!, we got'it string"); 29 | else 30 | printf("No!, we don't got'it"); 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Handling Multiple String) - Assignment-19/sortString.c: -------------------------------------------------------------------------------- 1 | #include 2 | void strSort(char str[]) 3 | { 4 | for (int i = 0; str[i]; i++) 5 | { 6 | for (int j = i + 1; str[j]; j++) 7 | { 8 | if (str[i] > str[j]) 9 | { 10 | char ch = str[i]; 11 | str[i] = str[j]; 12 | str[j] = ch; 13 | } 14 | } 15 | } 16 | } 17 | int main() 18 | { 19 | char str[10][100]; 20 | for (int i = 0; i < 10; i++) 21 | fgets(str[i], 100, stdin); 22 | 23 | printf("Sorted string: \n"); 24 | for (int i = 0; i < 10; i++) 25 | { 26 | strSort(str[i]); 27 | printf("%s", str[i]); 28 | } 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/Hello_Students.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | printf("Hello Students"); 4 | return 0; 5 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/Hello_Students2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | printf("Hello\nStudents"); 4 | return 0; 5 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/areaOfCircle.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int radius; 4 | printf("Enter the radius: "); 5 | scanf("%d",&radius); 6 | printf("Area of circle is %f having the radius %d",3.14*radius*radius, radius); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/findOutput.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int x = printf("ineuron"); 4 | printf("%d",x); 5 | return 0; 6 | } 7 | s 8 | //Answer - 7 -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/lengthOfStringUsingPrintf.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("Length of string is: %d",printf("String")); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/print-%d-OnScreen.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("%%d"); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/printDOBFormatUsingSlash.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int dd, mm, yyyy; 5 | printf("Enter date,month,year: "); 6 | scanf("%d",&dd); 7 | printf("%d/",dd); 8 | scanf("%d",&mm); 9 | printf("%d/%d/",dd,mm); 10 | scanf("%d",&yyyy); 11 | printf("%d/%d/%d",dd,mm,yyyy); 12 | 13 | printf("\nmDay - %d,Month - %d, Year - %d", dd, mm, yyyy); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/printDoubleSlash.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("\\\\"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/printHour&Minute.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int hh,mm; 5 | printf("Input hour and minute\n"); 6 | scanf("%d",&hh); 7 | printf("%d:",hh); 8 | scanf("%d",&mm); 9 | printf("%d Hour and %d Minute",hh,mm); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/printMySirgWithDoubleQuotes.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | printf("\"MySirgG\""); 4 | return 0; 5 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/printUserNameWithDoubleQuotes.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("\"Hello, Silent Night\""); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Input,Output)-Assignment-1/printnewline.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("\\n"); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/ArmstrongNum.c: -------------------------------------------------------------------------------- 1 | // 153 = 1 + 125 + 27 2 | #include 3 | int main() 4 | { 5 | int num; 6 | printf("Enter numbre for checking armstrong numnber: "); 7 | scanf("%d", &num); 8 | int sum = 0; 9 | for (int i = num; i != 0; i /= 10) 10 | { 11 | int rem = i % 10; 12 | sum += rem * rem * rem; 13 | } 14 | if (sum == num) 15 | printf("Armstrong number"); 16 | else 17 | printf("Not Armstrong number"); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/ArmstrongNumUnder100.c: -------------------------------------------------------------------------------- 1 | // 153 = 1 + 125 + 27 2 | #include 3 | int main() 4 | { 5 | for (int j = 1; j <= 1000; j++) 6 | { 7 | int sum; 8 | for (int j = 1; j <= 1000; j++) 9 | { 10 | sum = 0; 11 | for (int i = j; i != 0; i /= 10) 12 | { 13 | int rem = i % 10; 14 | sum += rem * rem * rem; 15 | } 16 | if (sum == j) 17 | printf("%d ", j); 18 | } 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/Co_PrimeNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int x, y; 5 | printf("Enter two number: "); 6 | scanf("%d%dd", &x, &y); 7 | int flag = 1; 8 | int condition = x < y ? x : y; 9 | for (int i = 2; i <= condition; i++) 10 | { 11 | if (x % i == 0 && y % i == 0) 12 | { 13 | flag = 0; 14 | break; 15 | } 16 | } 17 | if (flag) 18 | printf("It is co-prime no"); 19 | else 20 | printf("It is not co-prime no."); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/Fibonacci_series.c: -------------------------------------------------------------------------------- 1 | // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on. 2 | #include 3 | int main() 4 | { 5 | int n; 6 | int x = 0, y = 1; 7 | int sum=0; 8 | printf("Enter the value: "); 9 | scanf("%d", &n); 10 | if (n == 1) 11 | printf("%d finbonacci series no. is: %d",n,0); 12 | else if (n == 2) 13 | printf("%d finbonacci series no. is: %d",n,1); 14 | else 15 | { 16 | for (int i = 3; i <= n; i++) 17 | { 18 | sum = x + y; 19 | x = y; 20 | y = sum; 21 | } 22 | printf("%d finbonacci series no. is: %d",n,sum); 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/HCF.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int x, y; 5 | printf("Enter two number: "); 6 | scanf("%d%d", &x, &y); 7 | int hcf; 8 | for (int i = x>y?x:y; i >= 1; i--) 9 | { 10 | if (x % i == 0 && y % i == 0) 11 | { 12 | hcf = i; 13 | break; 14 | } 15 | } 16 | printf("HCF is: %d", hcf); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/checkGivenNumFibonacciSeriesBelongorNot.c: -------------------------------------------------------------------------------- 1 | // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on. 2 | #include 3 | int main() 4 | { 5 | int n; 6 | printf("Enter Number: "); 7 | scanf("%d", &n); 8 | int x = 0, y = 1; 9 | int sum = 0, flag = 0; 10 | if (n == 0 || n == 1) 11 | flag = 1; 12 | else 13 | { 14 | for (int i = 3; i <= n; i++) 15 | { 16 | sum = x + y; 17 | x = y; 18 | y = sum; 19 | if (n == sum) 20 | { 21 | flag = 1; 22 | break; 23 | } 24 | } 25 | } 26 | if (flag) 27 | printf("Yup!, it is belong. "); 28 | else 29 | printf("Oops!, it is not belong. "); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/firstNtermFibonacciSeries.c: -------------------------------------------------------------------------------- 1 | // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on. 2 | #include 3 | int main() 4 | { 5 | int n; 6 | printf("How many terms you want to print: "); 7 | scanf("%d", &n); 8 | int x = 0, y = 1; 9 | int sum=0; 10 | if (n == 1) 11 | printf("0 "); 12 | else if (n == 2) 13 | printf("1 "); 14 | else 15 | { 16 | printf("0 1 "); 17 | for (int i = 3; i <= n; i++) 18 | { 19 | sum = x + y; 20 | x = y; 21 | y = sum; 22 | printf("%d ",sum); 23 | } 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/nextPrimeNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter number: "); 6 | scanf("%d", &n); 7 | int i = n + 1, j, flag = 1; 8 | int nextPrimeNum; 9 | while (1) 10 | { 11 | flag = 1; 12 | for (int j = 2; j <= i / 2; j++) 13 | { 14 | if (i % j == 0) 15 | { 16 | flag = 0; 17 | break; 18 | } 19 | } 20 | if (flag) 21 | { 22 | printf("Next Prime num: %d", i); 23 | break; 24 | } 25 | i++; 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/printPrimeNumBetGivenRang.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int start, end; 5 | printf("Enter starting and ending range: "); 6 | scanf("%d%d", &start, &end); 7 | int i, j, flag = 1; 8 | for (i = start; i <= end; i++) 9 | { 10 | flag = 1; 11 | for (j = 2; j <= i / 2; j++) 12 | { 13 | if (i % j == 0) 14 | { 15 | flag = 0; 16 | break; 17 | } 18 | } 19 | if (flag) 20 | printf("%d ", i); 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do-while) - Assignment 7 #4/printPrimeUnder100.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,flag=1; 5 | for (i = 1; i <= 100; i++) 6 | { 7 | flag = 1; 8 | for (j = 2; j <= i / 2; j++) 9 | { 10 | if (i % j == 0) 11 | { 12 | flag = 0; 13 | break; 14 | } 15 | } 16 | if (flag) 17 | printf("%d ", i); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/countDigitOfNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter number: "); 6 | scanf("%d", &num); 7 | int count = 0; 8 | for (int i = num; i != 0; i /= 10) 9 | count++; 10 | printf("%d Number, Total Digit is: %d", num, count); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/factoral.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter a number, for print factoral of these number: "); 6 | scanf("%d", &n); 7 | int fact = 1; 8 | for (int i = 2; i <= n; i++) 9 | fact *= i; 10 | printf("%d number factoral is: %d", n, fact); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/lcmOfTwoNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int x, y; 5 | printf("Enter two number, for lcm: "); 6 | scanf("%d%d", &x, &y); 7 | int lcm = 1; 8 | int i = 1; 9 | while (1) 10 | { 11 | if (i % x == 0 && i % y == 0) 12 | { 13 | lcm = i; 14 | break; 15 | } 16 | i++; 17 | } 18 | printf("LCM is: %d", lcm); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/primeOrNot.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num,i; 5 | printf("Enter number for check prime or not: "); 6 | scanf("%d", &num); 7 | for (i = 2; i <= num / 2; i++) 8 | if (num % i == 0) 9 | break; 10 | if (i == num / 2 + 1) 11 | printf("Prime Number"); 12 | else 13 | printf("Not Prime Number"); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/reverseOfNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter a number: "); 6 | scanf("%d", &n); 7 | int reverseNumber = 0, ct = 0, flag = 1; 8 | while (n != 0) 9 | { 10 | if (n % 10 == 0 && flag) 11 | ct++; 12 | else 13 | flag = 0; 14 | reverseNumber = reverseNumber * 10 + n % 10; 15 | n /= 10; 16 | } 17 | printf("Reverse number is: "); 18 | if (ct != 0) 19 | for (int i = 1; i <= ct; i++) 20 | printf("0"); 21 | printf("%d", reverseNumber); 22 | return 0; 23 | } 24 | 25 | // 1 2 3 3 * 10 + 2 = 32 * 100 + 1 -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/sumOfFirstNNaturalNumCube.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many numbers squares sum you want to print: "); 6 | scanf("%d", &n); 7 | int sum = 0; 8 | for (int i = 1; i <= n; i++) 9 | sum += i * i * i; 10 | printf("%d odd number sum is: %d", n, sum); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/sumOfFirstNNumberSquare.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many numbers squares sum you want to print: "); 6 | scanf("%d", &n); 7 | int sum = 0; 8 | for (int i = 1; i <= n; i++) 9 | sum += i * i; 10 | printf("%d odd number sum is: %d", n, sum); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/sumOfFirstNOddNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many odd number sum you want to print: "); 6 | scanf("%d",&n); 7 | int sum = 0; 8 | for(int i=1; i<2*n; i+=2) 9 | sum+=i; 10 | printf("%d odd number sum is: %d",n,sum); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/sumOfFirstNevenNaturalnum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many even number sum you want to print: "); 6 | scanf("%d",&n); 7 | int sum = 0; 8 | for(int i=2; i<=2*n; i+=2) 9 | sum+=i; 10 | printf("%d even number sum is: %d",n,sum); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,While,Do_while) - Assignment-6 #3/sumOfFirstNnaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many number sum you want to print: "); 6 | scanf("%d", &n); 7 | int sum = 0; 8 | for (int i = 1; i <= n; i++) 9 | sum += i; 10 | printf("Sum is %d\n", sum); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/cubeOfFirst10NaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | for(int i=1; i<=10; i++) 5 | printf("%d ",i*i*i); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/first10EvenNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | for (i = 2; i <= 20; i += 2) 6 | printf("%d ", i); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/first10EvenNaturalNum_ReverseOrder.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | for(i=20; i>=2; i-=2) 6 | printf("%d ",i); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/first10OddNaturalNumReverseOrder.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | for (i = 19; i >= 1; i -= 2) 6 | printf("%d ", i); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/printFirst10NaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | for(int i=1; i<=10; i++) 6 | printf("%d ",i); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/printFirst10NaturalNumIn_ReverseOrder.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i = 11; 5 | while (--i) 6 | printf("%d ", i); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/printMySirg5time.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | for(i=1; i<=5; i++) 6 | printf("MySirG "); 7 | return 0; 8 | }ḥ -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/printTableOf_5.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | for (int i = 1; i <= 10; i++) 5 | printf("%d\n", i * 5); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/printfFirst10OddNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | for (int i = 1; i < 20; i += 2) 6 | printf("%d ", i); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment-4 #1/squareOffirst10NaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i; 5 | for (i = 1; i <= 10; i++) 6 | printf("%d ", i * i); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_NaturalNum_Square.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter how many number, square you want to print: "); 6 | scanf("%d", &n); 7 | for (int i = 1; i <= n; i++) 8 | printf("%d ", i * i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_evenNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many even number you want to print: "); 6 | scanf("%d", &n); 7 | for (int i = 2; i <= 2 * n; i += 2) 8 | printf("%d ", i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_evenNum_ReverseOrder.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter how many even number you want to print in reversre order: "); 6 | scanf("%d", &n); 7 | for (int i = 2 * n; i >= 2; i -= 2) 8 | printf("%d ", i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_naturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many Natural Number you want to print: "); 6 | scanf("%d", &n); 7 | for (int i = 1; i <= n; i++) 8 | printf("%d ", i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_naturalNum_Cube.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter how many number, cube you want to print: "); 6 | scanf("%d", &n); 7 | for (int i = 1; i <= n; i++) 8 | printf("%d ", i * i * i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_naturalNum_ReverseOrder.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many Natural Number you want to print: "); 6 | scanf("%d", &n); 7 | for (int i = n; i >= 1; i--) 8 | printf("%d ", i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_oddNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many odd number you want to print: "); 6 | scanf("%d", &n); 7 | for (int i = 1; i < 2 * n; i += 2) 8 | printf("%d ", i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/first_N_oddNaturalNum_ReverseOrder.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many odd number you want to print in Reverse Order: "); 6 | scanf("%d", &n); 7 | for (int i = 2 * n - 1; i >= 1; i -= 2) 8 | printf("%d ", i); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/mysirg_N_times.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("How many times you want to print MySirG on the screen: "); 6 | scanf("%d", &n); 7 | for (int i = 1; i <= n; i++) 8 | printf("MySirG\n"); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Loops-For,Whilte,Do_while) - Assignment5 #2/table_of_N.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Which number table you want to print: "); 6 | scanf("%d", &n); 7 | int i = 1; 8 | while (i <= 10) 9 | { 10 | printf("%d\n", i * n); 11 | i++; 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/findSquare.c: -------------------------------------------------------------------------------- 1 | #include 2 | int square(int n) 3 | { 4 | return n * n; 5 | } 6 | int main() 7 | { 8 | int n; 9 | printf("Enter any number: "); 10 | scanf("%d", &n); 11 | printf("Square is: %d", square(n)); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/findSumOFSeries.c: -------------------------------------------------------------------------------- 1 | // 1! /1+2!/2+3!/3+4!/4+5!/5 2 | #include 3 | int fact(int n) 4 | { 5 | int fact = 1; 6 | for (int i = 2; i <= n; i++) 7 | fact *= i; 8 | return fact; 9 | } 10 | int sumOfTheSeries(int term) 11 | { 12 | int sum = 0; 13 | for (int i = 1; i <= term; i++) 14 | { 15 | sum += fact(i) / i; 16 | } 17 | return sum; 18 | } 19 | int main() 20 | { 21 | int term; 22 | printf("How many terms sum you need: "); 23 | scanf("%d", &term); 24 | printf("Sum is: %d", sumOfTheSeries(term)); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/firstNPrimeNum_TSRN.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int firstNPrime(int n) 4 | { 5 | int i = 1, j; 6 | while (n) 7 | { 8 | for (j = 2; j <= i / 2; j++) 9 | { 10 | if (i % j == 0) 11 | break; 12 | } 13 | if (j - 1 == i / 2) 14 | { 15 | printf("%d ", i); 16 | n--; 17 | } 18 | i++; 19 | } 20 | } 21 | int main() 22 | { 23 | int n; 24 | printf("Enter a number: "); 25 | scanf("%d", &n); 26 | firstNPrime(n); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/hcf_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | int hcf(int n1,int n2) 3 | { 4 | int i; 5 | for(i=n1=1; i--) 6 | if(n1%i==0 && n2%i==0) 7 | break; 8 | return i; 9 | } 10 | int main(){ 11 | int n1,n2; 12 | printf("Enter two number: "); 13 | scanf("%d%d",&n1,&n2); 14 | printf("LCM is: %d",hcf(n1,n2)); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/lcm_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | int lcm(int n1,int n2) 3 | { 4 | int i; 5 | for(i=n1>n2?n1:n2; i<=n1*n2; i++) 6 | if(i%n1==0 && i%n2==0) 7 | break; 8 | return i; 9 | } 10 | int main(){ 11 | int n1,n2; 12 | printf("Enter two number: "); 13 | scanf("%d%d",&n1,&n2); 14 | printf("LCM is: %d",lcm(n1,n2)); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/nextPrimeNumber_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int nextPrime(int num) 4 | { 5 | int i = num + 1, j; 6 | while (1) 7 | { 8 | for (j = 2; j <= i/2; j++) 9 | { 10 | if (i % j == 0) 11 | break; 12 | } 13 | if (j-1 == i/2) 14 | break; 15 | i++; 16 | } 17 | return i; 18 | } 19 | int main() 20 | { 21 | int num; 22 | printf("Enter a number: "); 23 | scanf("%d", &num); 24 | printf("Next Prime Number is: %d", nextPrime(num)); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/pascalTriangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fact(int n) 3 | { 4 | int fact = 1; 5 | for (int i = 1; i <= n; i++) 6 | fact *= i; 7 | return fact; 8 | } 9 | 10 | void pascalTriangle(int lines) 11 | { 12 | int k,col; 13 | for (int i = 1; i <= lines; i++) 14 | { 15 | k = 1,col=0; 16 | for (int j = 1; j < 2 * lines; j++) 17 | { 18 | if (k && j >= (lines + 1) - i && j <= (lines - 1) + i) 19 | { 20 | printf("%d ",fact(i-1)/(fact(i-1-col)*fact(col))); 21 | col++; 22 | k = 0; 23 | } 24 | else 25 | { 26 | printf(" "); 27 | k = 1; 28 | } 29 | } 30 | printf("\n"); 31 | } 32 | } 33 | int main() 34 | { 35 | int lines; 36 | printf("How many lines you want to print: "); 37 | scanf("%d", &lines); 38 | pascalTriangle(lines); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/primeNumber_TSRS.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int prime(int num) 4 | { 5 | int i; 6 | for(i=2; i 2 | void fibo(int n) 3 | { 4 | if(n==1) 5 | printf("0 "); 6 | else if(n==2) 7 | printf("0 1"); 8 | else 9 | { 10 | int x=0,y=1; 11 | printf("0 1 "); 12 | for(int i=3; i<=n; i++) 13 | { 14 | int sum = x+y; 15 | x = y; 16 | y = sum; 17 | printf("%d ",sum); 18 | } 19 | } 20 | } 21 | int main() 22 | { 23 | int term; 24 | printf("How many terms you want to print: "); 25 | scanf("%d",&term); 26 | fibo(term); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/printPrimeGivenRange_TSRN.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void prime(int x, int y) 4 | { 5 | int i, j; 6 | for (i = x; i <= y; i++) 7 | { 8 | for (j = 2; j <= i/2; j++) 9 | { 10 | if (i % j == 0) 11 | break; 12 | } 13 | if (j - 1 == i/2) 14 | printf("%d ", i); 15 | } 16 | } 17 | int main() 18 | { 19 | int a, b; 20 | printf("Enter the two number: "); 21 | scanf("%d%d", &a, &b); 22 | prime(a, b); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Function) - Assignment-11/tempCodeRunnerFile.c: -------------------------------------------------------------------------------- 1 | return -1; 2 | } 3 | int main(){ 4 | int n1,n2; 5 | printf("Enter two number: "); 6 | scanf("%d%d",&n1,&n2); 7 | printf("LCM is: %d",lcm(n1,n2)); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/digitCount.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n) 3 | { 4 | int ct=0; 5 | if (n == 0) 6 | return 0; 7 | ct++; 8 | return ct + fun(n/10); 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d", &n); 15 | printf("count is: %d", fun(n)); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n) 3 | { 4 | if (n == 1) 5 | return 1; 6 | return n * fun(n-1); 7 | } 8 | int main() 9 | { 10 | int n; 11 | printf("Enter the value: "); 12 | scanf("%d", &n); 13 | printf("Sum is: %d", fun(n)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/fibonacci_series.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Fibonacci(int n) 4 | { 5 | if (n == 0) 6 | return 0; 7 | else if (n == 1) 8 | return 1; 9 | else 10 | return (Fibonacci(n - 1) + Fibonacci(n - 2)); 11 | } 12 | 13 | int main() 14 | { 15 | int n, i = 0, c; 16 | scanf("%d", &n); 17 | printf("Fibonacci series - "); 18 | for (c = 1; c <= n; c++) 19 | { 20 | printf("%d ", Fibonacci(i)); 21 | i++; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/hcf.c: -------------------------------------------------------------------------------- 1 | #include 2 | int hcf(int a, int b) 3 | { 4 | if (a == b) 5 | return a; 6 | else if (a % b == 0) 7 | return b; 8 | else if (b % a == 0) 9 | return a; 10 | if (a > b) 11 | return gcd(a % b, b); 12 | else 13 | return gcd(a, b % a); 14 | } 15 | int main() 16 | { 17 | int x, y; 18 | printf("Enter two number: "); 19 | scanf("%d%d", &x, &y); 20 | printf("hcf is: %d", hcf(x, y)); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/powerOfNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n,int p) 3 | { 4 | if (p == 0) 5 | return 1; 6 | return n * fun(n,p-1); 7 | } 8 | int main() 9 | { 10 | int n,power; 11 | printf("Enter the value and it's power: "); 12 | scanf("%d%d", &n,&power); 13 | printf("power is: %d", fun(n,power)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/sumOfDigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n) 3 | { 4 | if (n == 0) 5 | return 0; 6 | return n%10 + fun(n/10); 7 | } 8 | int main() 9 | { 10 | int n; 11 | printf("Enter the value: "); 12 | scanf("%d", &n); 13 | printf("Sum is: %d", fun(n)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/sumOfEvenNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n) 3 | { 4 | if (n == 0) 5 | return 0; 6 | return (n*2) + fun(n - 1); 7 | } 8 | int main() 9 | { 10 | int n; 11 | printf("Enter the value: "); 12 | scanf("%d", &n); 13 | printf("Sum is: %d", fun(n)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/sumOfFirstNnaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n) 3 | { 4 | if (n == 1) 5 | return 1; 6 | return n + fun(n - 1); 7 | } 8 | int main() 9 | { 10 | int n; 11 | printf("Enter the value: "); 12 | scanf("%d", &n); 13 | printf("Sum is: %d", fun(n)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/sumOfFirstOddNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n) 3 | { 4 | if (n == 1) 5 | return 1; 6 | return (n*2-1) + fun(n - 1); 7 | } 8 | int main() 9 | { 10 | int n; 11 | printf("Enter the value: "); 12 | scanf("%d", &n); 13 | printf("Sum is: %d", fun(n)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/sumOfSquareNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fun(int n) 3 | { 4 | if (n == 0) 5 | return 0; 6 | return (n*n) + fun(n - 1); 7 | } 8 | int main() 9 | { 10 | int n; 11 | printf("Enter the value: "); 12 | scanf("%d", &n); 13 | printf("Sum is: %d", fun(n)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(More On Recursion) - Assignment-13/tempCodeRunnerFile.c: -------------------------------------------------------------------------------- 1 | 2 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Multi-DimestionArray) - Assignment - 16/leftDiagonalsSum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int row, leftDiagoSum = 0; 5 | printf("Enter Row of Matrix: "); 6 | scanf("%d", &row); 7 | 8 | int matrix[row][row]; 9 | printf("Enter Element in %d*%d Matrix: \n", row, row); 10 | for (int i = 0; i < row; i++) 11 | for (int j = 0; j < row; j++) 12 | scanf("%d", &matrix[i][j]); 13 | 14 | // find left Diagonal Sum 15 | for (int i = 0, j = row - 1 - i; i < row; i++, j--) 16 | leftDiagoSum += matrix[i][j]; 17 | 18 | // print Matrix 19 | printf("Given Matrix: \n"); 20 | for (int i = 0; i < row; i++) 21 | { 22 | for (int j = 0; j < row; j++) 23 | printf("%d ", matrix[i][j]); 24 | printf("\n"); 25 | } 26 | 27 | // right Diagonalls sum 28 | printf("left Diagonals of Matrix Sum is: %d\n", leftDiagoSum); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Multi-DimestionArray) - Assignment - 16/printLowerTriangleMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int row; 5 | printf("Enter Row of Matrix: "); 6 | scanf("%d", &row); 7 | 8 | int matrix[row][row]; 9 | printf("Enter Element in %d*%d Matrix: \n", row, row); 10 | for (int i = 0; i < row; i++) 11 | for (int j = 0; j < row; j++) 12 | scanf("%d", &matrix[i][j]); 13 | 14 | // print Matrix 15 | printf("Given Matrix: \n"); 16 | for (int i = 0; i < row; i++) 17 | { 18 | for (int j = 0; j < row; j++) 19 | printf("%d ", matrix[i][j]); 20 | printf("\n"); 21 | } 22 | 23 | // print Lower triangular Matrix 24 | printf("lower triangular Matrix: \n"); 25 | for (int i = 0; i < row; i++) 26 | { 27 | for (int j = 0; j <= i; j++) 28 | printf("%d ", matrix[i][j]); 29 | printf("\n"); 30 | } 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Multi-DimestionArray) - Assignment - 16/rightDiagonalSum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int row, rightDiagoSum=0; 5 | printf("Enter Row of Matrix: "); 6 | scanf("%d", &row); 7 | 8 | int matrix[row][row]; 9 | printf("Enter Element in %d*%d Matrix: \n", row, row); 10 | for (int i = 0; i < row; i++) 11 | { 12 | for (int j = 0; j < row; j++) 13 | { 14 | scanf("%d", &matrix[i][j]); 15 | if (i == j) 16 | rightDiagoSum += matrix[i][j]; 17 | } 18 | } 19 | 20 | // print Matrix 21 | printf("Given Matrix: \n"); 22 | for (int i = 0; i < row; i++) 23 | { 24 | for (int j = 0; j < row; j++) 25 | printf("%d ", matrix[i][j]); 26 | printf("\n"); 27 | } 28 | 29 | // right Diagonalls sum 30 | printf("Right Diagonals of Matrix Sum is: %d\n", rightDiagoSum); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Multi-DimestionArray) - Assignment - 16/sumOfMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int row, col, sumOfMatrix = 0; 5 | printf("Enter Row and Column of Matrix: "); 6 | scanf("%d%d", &row, &col); 7 | 8 | int matrix[row][col]; 9 | printf("Enter Element in %d*%d Matrix: \n", row, col); 10 | for (int i = 0; i < row; i++) 11 | { 12 | for (int j = 0; j < col; j++) 13 | { 14 | scanf("%d", &matrix[i][j]); 15 | sumOfMatrix += matrix[i][j]; 16 | } 17 | } 18 | 19 | // print Matrix 20 | printf("Given Matrix: \n"); 21 | for (int i = 0; i < row; i++) 22 | { 23 | for (int j = 0; j < row; j++) 24 | printf("%d ", matrix[i][j]); 25 | printf("\n"); 26 | } 27 | 28 | // matrix sum 29 | printf("Matrix All Element Sum is: %d\n", sumOfMatrix); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Multi-DimestionArray) - Assignment - 16/transposeOfMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int row, col; 5 | printf("Enter Row and Column of Matrix: "); 6 | scanf("%d%d", &row, &col); 7 | 8 | int matrix[row][col]; 9 | printf("Enter Element in %d*%d Matrix: \n", row, col); 10 | for (int i = 0; i < row; i++) 11 | for (int j = 0; j < col; j++) 12 | scanf("%d", &matrix[i][j]); 13 | 14 | // print Matrix 15 | printf("Given Matrix: \n"); 16 | for (int i = 0; i < row; i++) 17 | { 18 | for (int j = 0; j < col; j++) 19 | printf("%d ", matrix[i][j]); 20 | printf("\n"); 21 | } 22 | 23 | // find Transpose, here we only find Transpose not assign according to question 24 | printf("Transpose of Matrix: \n"); 25 | for (int i = 0; i < col; i++) 26 | { 27 | for (int j = 0; j < row; j++) 28 | printf("%d ", matrix[j][i]); 29 | printf("\n"); 30 | } 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/appendDigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num, digit; 5 | printf("Enter a number and also input a digit: "); 6 | scanf("%d%d", &num, &digit); 7 | int newNumber = num * 10 + digit; 8 | printf("New number is: %d", newNumber); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/convertUSDtoINR.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | float priceUSD = 76.23; 5 | int inr; 6 | printf("Enter a amount of INR: "); 7 | scanf("%d",&inr); 8 | float totalUsdAmount = inr*priceUSD; 9 | printf("total amount in usd is: %f",totalUsdAmount); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/evenOddUsingBitwise.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | num & 1 ? printf("odd") : printf("even"); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/makeLastDigitOfNumberZero.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | int newNumber = (num/10) * 10; 8 | printf("New number is: %d",newNumber); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/printASCIICodeOfGivenCharacter.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | char ch; 5 | printf("Enter a character: "); 6 | scanf("%c",&ch); 7 | printf("Ascii code is: %d",ch); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/printNumberWithoutLastDigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Input a number: "); 6 | scanf("%d",&num); // 538 7 | int userNumberWithoutLastDigit = num / 10; 8 | printf("User number: %d",userNumberWithoutLastDigit); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/printSizeOfDataTypes.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("Sizeof int is: %d\n", sizeof(int)); // 4 5 | printf("Sizeof float is: %d\n", sizeof(float)); // 4 6 | printf("Size of char is: %d\n", sizeof(char)); // 1 7 | printf("Size of double is: %d\n", sizeof(double)); // 8 8 | return 0; 9 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/sumOfThreeDigitNumber.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | int num; 4 | printf("Enter a number "); 5 | scanf("%d", &num); 6 | int digitSum = num%10; 7 | num = num/10; 8 | digitSum+=num%10; 9 | num = num/10; 10 | digitSum+=num%10; 11 | printf("Sum of digit is: %d",digitSum); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/swapTwoIntegerWithoutThirdVariable.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num1, num2; 5 | printf("Enter a two number: "); 6 | scanf("%d%d", &num1, &num2); // 1,2 7 | printf("Before swap: a = %d,b = %d", num1, num2); 8 | num1 = num1 + num2; // 3 9 | num2 = num1 - num2; // 1 10 | num1 = num1 - num2; // 2 11 | printf("\nAfter swap: a = %d,b = %d", num1, num2); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/swapTwoValue.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num1,num2; 5 | printf("Enter a two number: "); 6 | scanf("%d%d",&num1,&num2); 7 | printf("Before swap: a = %d,b = %d",num1,num2); 8 | int temp = num1; 9 | num1 = num2; 10 | num2 = temp; 11 | printf("\nAfter swap: a = %d,b = %d",num1,num2); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/take3DigitNumRoateByOne.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Enter a number: "); 6 | scanf("%d", &num); 7 | int rem = num % 10; 8 | if (rem == 0) 9 | { 10 | printf("one position towards the right ans: "); 11 | rem = rem * 100 + num / 10; 12 | printf("one position towards the right ans: 0%d", rem); 13 | } 14 | else 15 | { 16 | rem = rem * 100 + num / 10; 17 | printf("one position towards the right ans: %d", rem); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C Language Assignments/C(Operators)-Assignment-2/unitDigitOfGivenNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num; 5 | printf("Input a number: "); 6 | scanf("%d",&num); 7 | int unit_digit = num%10; 8 | printf("Unit digit is: %d",unit_digit); 9 | return 0; 10 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/lengthOfString.c: -------------------------------------------------------------------------------- 1 | #include 2 | int length(char *ptr) 3 | { 4 | int i; 5 | for (i = 0; *(ptr + i); i++) 6 | ; 7 | return i-1; // becuase fgets function contain \n extra 8 | } 9 | int main() 10 | { 11 | char str[20]; 12 | printf("Enter string: "); 13 | fgets(str, 20, stdin); 14 | int l = length(str); 15 | printf("length of string: %d", l); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/maxNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int x, y; 5 | printf("Enter two number: "); 6 | scanf("%d%d", &x, &y); 7 | int *p = &x, *q = &y; 8 | if (*p > *q) 9 | printf("Max Num is: %d", *p); 10 | else 11 | printf("Max Num is: %d", *q); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/printStringReverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void reverseStringPrint(char *ptr) 4 | { 5 | int length = strlen(ptr)-1; 6 | for(int i = length; i>=0; i--) 7 | printf("%c", *(ptr+i)); 8 | } 9 | int main() 10 | { 11 | char arr[20]; 12 | printf("Enter string: "); 13 | fgets(arr, 20, stdin); 14 | reverseStringPrint(arr); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/reverseArrayPrint.c: -------------------------------------------------------------------------------- 1 | #include 2 | void reverseArrayPrint(int *ptr, int n) 3 | { 4 | for(int i = n-1; i>=0; i--) 5 | printf("%d ",*(ptr+i)); 6 | } 7 | int main() 8 | { 9 | int n; 10 | printf("\nhow many number u want to enter : "); 11 | scanf("%d", &n); 12 | int arr[n]; 13 | printf("Enter %d element: \n", n); 14 | for (int i = 0; i < n; i++) 15 | scanf("%d", &arr[i]); 16 | reverseArrayPrint(arr, n); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/sortArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | void sortArray(int *ptr, int size) 3 | { 4 | for (int i = 0; i < size; i++) 5 | { 6 | for (int j = i + 1; j < size; j++) 7 | { 8 | if (*(ptr + i) > *(ptr + j)) 9 | { 10 | int temp = *(ptr + i); 11 | *(ptr + i) = *(ptr + j); 12 | *(ptr + j) = temp; 13 | } 14 | } 15 | } 16 | } 17 | int main() 18 | { 19 | int size; 20 | printf("Enter the array size: "); 21 | scanf("%d", &size); 22 | int arr[size]; 23 | printf("Enter %d Element in array\n", size); 24 | for (int i = 0; i < size; i++) 25 | scanf("%d", &arr[i]); 26 | sortArray(arr, size); 27 | printf("\nAfter Sorting: "); 28 | for (int i = 0; i < size; i++) 29 | printf("%d ", arr[i]); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/sumOfArray.c: -------------------------------------------------------------------------------- 1 | #include 2 | int sumOfArray(int *ptr, int n) 3 | { 4 | int sum = 0; 5 | for (int i = 0; i < n; i++) 6 | sum += *(ptr + i); 7 | return sum; 8 | } 9 | int main() 10 | { 11 | int n; 12 | printf("\nhow many number u want to enter : "); 13 | scanf("%d", &n); 14 | int arr[n]; 15 | printf("Enter %d element: \n", n); 16 | for (int i = 0; i < n; i++) 17 | scanf("%d", &arr[i]); 18 | int sum = sumOfArray(arr, n); 19 | printf("\nSum of Array is: %d", sum); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/swapString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void swapString(char *, char *); 4 | int main() 5 | { 6 | char *ptr = "Hello"; 7 | char *str = "Welcome"; 8 | swapString(ptr, str); 9 | printf("\nAfter Swapping, a = %sb = %s", ptr, str); 10 | return 0; 11 | } 12 | void swapString(char *ptr, char *str) 13 | { 14 | char *temp = ptr; 15 | ptr = str; 16 | str = temp; 17 | } 18 | -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/swapValue.c: -------------------------------------------------------------------------------- 1 | #include 2 | void swap(int*, int*); 3 | int main() 4 | { 5 | int a, b; 6 | printf("Enter two number: "); 7 | scanf("%d%d", &a, &b); 8 | swap(&a, &b); 9 | printf("After Swapping, a = %d, b = %d", a, b); 10 | return 0; 11 | } 12 | void swap(int *x, int *y) 13 | { 14 | int t = *x; 15 | *x = *y; 16 | *y = t; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/tempCodeRunnerFile.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | return 0; 4 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Pointers) - Assignment-20/vowelAndConsonent.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int vowel = 0, consonent = 0; 5 | char str[20]; 6 | printf("Enter string: "); 7 | fgets(str, 20, stdin); 8 | char *ptr = str; 9 | for (int i = 0; *(ptr + i); i++) 10 | { 11 | if (*(ptr + i) == 'a' || *(ptr + i) == 'e' || *(ptr + i) == 'i' || *(ptr + i) == 'o' || *(ptr + i) == 'u' || *(ptr + i) == 'A' || *(ptr + i) == 'E' || *(ptr + i) == 'I' || *(ptr + i) == 'O' || *(ptr + i) == 'U') 12 | vowel += 1; 13 | else 14 | consonent += 1; 15 | } 16 | printf("\nGiven string, total vowel - %d, total consonent - %d", vowel, consonent - 2); // becuase space and \n neglegct 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/EvenNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | if (n > 0) 5 | { 6 | print(n - 1); 7 | printf("%d ", 2*n); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | print(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/ReverseOrderEven.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | if (n > 0) 5 | { 6 | printf("%d ", 2*n); 7 | print(n - 1); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | print(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/ReverseOrderNnaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | if (n > 0) 5 | { 6 | printf("%d ", 2*n-1); 7 | print(n - 1); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | print(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/ReverserOrderNatural.c: -------------------------------------------------------------------------------- 1 | #include 2 | void naturalNum(int n) 3 | { 4 | if (n > 0) 5 | { 6 | naturalNum(n - 1); 7 | printf("%d ", n); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | naturalNum(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/binary_to_octal.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | if (n > 0) 5 | { 6 | print(n/8); 7 | printf("%d",n%8); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | print(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/decimal_to_binary.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | if (n > 0) 5 | { 6 | print(n/2); 7 | printf("%d",n%2); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | print(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/n_naturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | void naturalNum(int n) 3 | { 4 | if (n > 0) 5 | { 6 | naturalNum(n - 1); 7 | printf("%d ", n); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | naturalNum(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/n_oddNaturalNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | void naturalNum(int n) 3 | { 4 | if (n > 0) 5 | { 6 | naturalNum(n - 1); 7 | printf("%d ", 2*n-1); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | naturalNum(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/reverse_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | if (n > 0) 5 | { 6 | printf("%d",n%10); 7 | print(n/10); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the number: "); 14 | scanf("%d",&n); 15 | print(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Recursion) - Assignment-12/square.c: -------------------------------------------------------------------------------- 1 | #include 2 | void print(int n) 3 | { 4 | if (n > 0) 5 | { 6 | print(n - 1); 7 | printf("%d ", n*n); 8 | } 9 | } 10 | int main() 11 | { 12 | int n; 13 | printf("Enter the value: "); 14 | scanf("%d",&n); 15 | print(n); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern10.c: -------------------------------------------------------------------------------- 1 | /* 2 | 123454321 3 | 1234 4321 4 | 123 321 5 | 12 21 6 | 1 1 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int lines; 13 | printf("Enter how many lines you want to print: "); 14 | scanf("%d", &lines); 15 | int k; 16 | for (int i = 1; i <= lines; i++) 17 | { 18 | k = 1; 19 | for (int j = 1; j <= lines * 2 - 1; j++) 20 | { 21 | if (j <= lines + 1 - i || j >= lines - 1 + i) 22 | { 23 | if (j <= lines + 1 - i) 24 | { 25 | printf("%d", k++); 26 | if(j==lines+1-1) 27 | k = j; 28 | } 29 | else 30 | printf("%d", --k); 31 | } 32 | else 33 | printf(" "); 34 | } 35 | printf("\n"); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern11.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | ** 4 | *** 5 | **** 6 | ***** 7 | **** 8 | *** 9 | ** 10 | * 11 | */ 12 | 13 | #include 14 | int main() 15 | { 16 | int i, j, lines; 17 | printf("How many lines of triangle you want to print: "); 18 | scanf("%d", &lines); 19 | int k = 0; 20 | for (i = 1; i <= lines; i++) 21 | { 22 | i <= ((lines + 1) / 2) ? k++ : k--; 23 | for (int j = 1; j <= (lines + 1) / 2; j++) 24 | { 25 | if (j <= k) 26 | printf("*"); 27 | else 28 | printf(" "); 29 | } 30 | printf("\n"); 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern12.c: -------------------------------------------------------------------------------- 1 | /* 2 | ******************* 3 | ***************** 4 | *************** 5 | ************* 6 | *********** 7 | ********* 8 | ******* 9 | ***** 10 | *** 11 | * 12 | */ 13 | 14 | #include 15 | int main() 16 | { 17 | int i, j, lines; 18 | printf("How many lines of triangle you want to print: "); 19 | scanf("%d", &lines); 20 | for (i = 1; i <= lines; i++) 21 | { 22 | for (j = 1; j <=lines*2-1; j++) 23 | { 24 | if(j>=i && j<=(lines*2) - i) 25 | printf("*"); 26 | else 27 | printf(" "); 28 | } 29 | printf("\n"); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern13.c: -------------------------------------------------------------------------------- 1 | /* 2 | 1 3 | 232 4 | 34543 5 | 4567654 6 | 567898765 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int i, j, lines,k=0; 13 | printf("How many lines of triangle you want to print: "); 14 | scanf("%d", &lines); 15 | for (i = 1; i <= lines; i++) 16 | { 17 | for (j = 1; j <=lines*2-1; j++) 18 | { 19 | if(j>=lines+1-i && j<=lines-1+i){ 20 | j<=lines?k++:k--; 21 | printf("%d",k); 22 | } 23 | else 24 | printf(" "); 25 | } 26 | printf("\n"); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern14.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * 4 | * * 5 | * * 6 | * * * * * 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int i, j, n; 13 | printf("How many lines of triangle you want to print: "); 14 | scanf("%d", &n); 15 | int k; 16 | for (i = 1; i <= n; i++) 17 | { 18 | for (int j = 1; j <=n; j++) 19 | { 20 | if (j == 1 || j == i) 21 | printf("*"); 22 | else 23 | printf(" "); 24 | } 25 | printf("\n"); 26 | if(i==n) 27 | for(int k=1; k<=n; k++) 28 | printf("*"); 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern15.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * 4 | * * 5 | * * 6 | * * * * * 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int i, j, n; 13 | printf("How many lines of triangle you want to print: "); 14 | scanf("%d", &n); 15 | int k; 16 | for (i = 1; i <= n; i++) 17 | { 18 | for (int j = 1; j <=2*n-1; j++) 19 | { 20 | if (j == 6-i || j == 4+i) 21 | printf("*"); 22 | else 23 | printf(" "); 24 | } 25 | printf("\n"); 26 | if(i==n) 27 | for(int k=1; k<=2*n-1; k++) 28 | printf("*"); 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern16.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * 4 | * * 5 | * * 6 | * * 7 | * * 8 | * * 9 | * * 10 | * * 11 | * * 12 | ******************* 13 | */ 14 | 15 | #include 16 | int main() 17 | { 18 | int i, j, n; 19 | printf("How many lines of triangle you want to print: "); 20 | scanf("%d", &n); 21 | int k; 22 | for (i = 1; i <= n; i++) 23 | { 24 | for (int j = 1; j <=2*n-1; j++) 25 | { 26 | if (j == n+1-i || j == n-1+i) 27 | printf("*"); 28 | else 29 | printf(" "); 30 | } 31 | printf("\n"); 32 | if(i==n) 33 | for(int k=1; k<=2*n-1; k++) 34 | printf("*"); 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern17.c: -------------------------------------------------------------------------------- 1 | /* 2 | 123454321 3 | 1234 4321 4 | 123 321 5 | 12 21 6 | 1 1 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int lines; 13 | printf("Enter how many lines you want to print: "); 14 | scanf("%d", &lines); 15 | int k; 16 | for (int i = 1; i <= lines; i++) 17 | { 18 | k = 'A'; 19 | for (int j = 1; j <= lines * 2 - 1; j++) 20 | { 21 | if (j <= lines + 1 - i || j >= lines - 1 + i) 22 | { 23 | if (j <= lines + 1 - i) 24 | { 25 | printf("%c", k++); 26 | if(j==lines+1-1) 27 | k = j; 28 | } 29 | else 30 | printf("%d", --k); 31 | } 32 | else 33 | printf(" "); 34 | } 35 | printf("\n"); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern18.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | *** 4 | ***** 5 | *** 6 | * 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int i, j, n; 13 | printf("How many lines of triangle you want to print: "); 14 | scanf("%d", &n); 15 | for (i = 1; i <= n; i++) 16 | { 17 | if (i <= n / 2 + 1) 18 | { 19 | for (int j = 1; j <= n; j++) 20 | { 21 | if (j >= n/2+2 - i && j <= n/2 + i) 22 | printf("*"); 23 | else 24 | printf(" "); 25 | } 26 | printf("\n"); 27 | } 28 | else 29 | { 30 | for (int j = 1; j <= n; j++) 31 | { 32 | if (j >= i-n/2 && j <=(n-(i-(n/2+1)))) 33 | printf("*"); 34 | else 35 | printf(" "); 36 | } 37 | printf("\n"); 38 | } 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern19.c: -------------------------------------------------------------------------------- 1 | /* 2 | 9876543210 3 | 876543210 4 | 76543210 5 | 6543210 6 | 543210 7 | 43210 8 | 3210 9 | 210 10 | 10 11 | 0 12 | */ 13 | 14 | #include 15 | int main() 16 | { 17 | int i, j, lines,k; 18 | printf("How many lines of triangle you want to print: "); 19 | scanf("%d", &lines); 20 | for (i = 1; i <= lines; i++) 21 | { 22 | k = lines-i; 23 | for (j = 1; j <=lines; j++) 24 | { 25 | if(j<=(lines+1) - i) 26 | printf("%d",k--); 27 | else 28 | printf(" "); 29 | } 30 | printf("\n"); 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/starPattern6.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * 4 | * * * 5 | * * * * 6 | * * * * * 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int i, j, lines,flag; 13 | printf("How many lines of triangle you want to print: "); 14 | scanf("%d", &lines); 15 | for (i = 1; i <= lines; i++) 16 | { 17 | flag=1; 18 | for (int j = 1; j <= 2 * lines - 1; j++) 19 | { 20 | if (j >= lines + 1 - i && j <= lines - 1 + i && flag) 21 | { 22 | printf("*"); 23 | flag = 0; 24 | } 25 | else 26 | { 27 | printf(" "); 28 | flag =1; 29 | } 30 | } 31 | printf("\n"); 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/startPattern1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | * 4 | * * 5 | * * * 6 | * * * * 7 | * * * * * 8 | 9 | */ 10 | 11 | #include 12 | int main() 13 | { 14 | int lines; 15 | printf("Enter how many lines you want to print: "); 16 | scanf("%d",&lines); 17 | int i,j; 18 | for(i=1; i<=lines; i++) 19 | { 20 | for(int j=1; j<=lines; j++) 21 | { 22 | if(j<=i) 23 | printf("*"); 24 | else 25 | printf(" "); 26 | } 27 | printf("\n"); 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/startPattern2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * * 4 | * * * 5 | * * * * 6 | * * * * * 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int lines; 13 | printf("Enter how many lines you want to print: "); 14 | scanf("%d",&lines); 15 | int i,j; 16 | for(i=1; i<=lines; i++) 17 | { 18 | for(int j=1; j<=lines; j++) 19 | { 20 | if(j>=(lines+1)-i) 21 | printf("*"); 22 | else 23 | printf(" "); 24 | } 25 | printf("\n"); 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/startPattern3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * * * * * 3 | * * * * 4 | * * * 5 | * * 6 | * 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int lines; 13 | printf("Enter how many lines you want to print: "); 14 | scanf("%d",&lines); 15 | int i,j; 16 | for(i=1; i<=lines; i++) 17 | { 18 | for(int j=1; j<=lines; j++) 19 | { 20 | if(j<=(lines+1)-i) 21 | printf("*"); 22 | else 23 | printf(" "); 24 | } 25 | printf("\n"); 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/startPattern5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | *** 4 | ***** 5 | ******* 6 | ********* 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int i, j, lines; 13 | printf("How many lines of triangle you want to print: "); 14 | scanf("%d", &lines); 15 | for (i = 1; i <= lines; i++) 16 | { 17 | for (int j = 1; j <= 2 * lines - 1; j++) 18 | { 19 | if (j >= lines + 1 - i && j <= lines - 1 + i) 20 | printf("*"); 21 | else 22 | printf(" "); 23 | } 24 | printf("\n"); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/startPattern7.c: -------------------------------------------------------------------------------- 1 | /* 2 | ********** 3 | **** **** 4 | *** *** 5 | ** ** 6 | * * 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int i, j, lines; 13 | printf("How many lines of triangle you want to print: "); 14 | scanf("%d", &lines); 15 | for (i = 1; i <= lines; i++) 16 | { 17 | for (int j = 1; j <= 2*lines-1; j++) 18 | { 19 | if (j<=(lines+1)-i || j>=(lines-1)+i) 20 | printf("*"); 21 | else 22 | printf(" "); 23 | } 24 | printf("\n"); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/startPattern8.c: -------------------------------------------------------------------------------- 1 | /* 2 | 1 3 | 1 2 1 4 | 1 2 3 2 1 5 | 1 2 3 4 3 2 1 6 | */ 7 | 8 | #include 9 | int main() 10 | { 11 | int k; 12 | for (int i = 1; i <= 4; i++) 13 | { 14 | k = 1; 15 | for (int j = 1; j <= 7; j++) 16 | { 17 | if (j >= 5 - i && j <=3 + i) 18 | { 19 | printf("%d",k); 20 | j<4?k++:k--; 21 | } 22 | else 23 | printf(" "); 24 | } 25 | printf("\n"); 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Star Pattern) Assignment-8/startPattern9.c: -------------------------------------------------------------------------------- 1 | /* 2 | ABCDEDCBA 3 | ABCD EDCB 4 | ABC CBA 5 | AB BA 6 | A A 7 | */ 8 | 9 | #include 10 | int main() 11 | { 12 | int lines; 13 | printf("Enter how many lines you want to print: "); 14 | scanf("%d", &lines); 15 | for (int i = 1; i <= lines; i++) 16 | { 17 | int k = 'A'; 18 | for (int j = 1; j <= lines * 2 - 1; j++) 19 | { 20 | if (j <= (lines + 1) - i || j >= (lines - 1) + i) 21 | { 22 | printf("%c", k); 23 | j < lines ? k++ : k--; 24 | } 25 | else 26 | { 27 | printf(" "); 28 | if (j == 4) 29 | k--; 30 | } 31 | } 32 | printf("\n"); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/alphaNumericString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int strAlphaNumeric(char str[]) 5 | { 6 | int digit = 0, alphabet = 0; 7 | for (int i = 0; str[i]; i++) 8 | if (str[i] >= '0' && str[i] <= '9') 9 | digit = 1; 10 | else if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z')) 11 | alphabet = 1; 12 | 13 | if (digit && alphabet) 14 | return 1; 15 | else 16 | return 0; 17 | } 18 | 19 | int main() 20 | { 21 | char str[100]; 22 | 23 | printf("Enter first string: "); 24 | fgets(str, 100, stdin); 25 | 26 | if (strAlphaNumeric(str)) 27 | printf("\nString is Alphanumeric!"); 28 | else 29 | printf("\nString is Not Alphanumeric!"); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/compareString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int strCompare(char str1[], char str2[]) 5 | { 6 | for (int i = 0; str1[i] || str2[i]; i++) 7 | { 8 | if (str1[i] != str2[i]) 9 | return 0; 10 | } 11 | if (strlen(str1) == strlen(str2)) 12 | return 1; 13 | return 0; 14 | } 15 | 16 | int main() 17 | { 18 | char str1[100], str2[100]; 19 | 20 | printf("Enter first string: "); 21 | fgets(str1, 100, stdin); 22 | 23 | printf("Enter second string: "); 24 | fgets(str2, 100, stdin); 25 | 26 | if (strCompare(str1, str2)) 27 | printf("\nString is equal"); 28 | else 29 | printf("\nString is not equal"); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/countWordsInString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int strCountWord(char str[]) 5 | { 6 | int countSpace = 1; 7 | for (int i = 0; str[i]; i++) 8 | if (str[i] == ' ') 9 | countSpace++; 10 | return countSpace; 11 | } 12 | 13 | int main() 14 | { 15 | char str[100]; 16 | 17 | printf("Enter first string: "); 18 | fgets(str, 100, stdin); 19 | 20 | printf("\nTotal words in given string: %d", strCountWord(str)); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/lengthOfStringFunnction.c: -------------------------------------------------------------------------------- 1 | #include 2 | int strLength(char str[]) 3 | { 4 | int i; 5 | for (i = 0; str[i]; i++); 6 | return i; 7 | } 8 | int main() 9 | { 10 | char str[100]; 11 | printf("Enter string: "); 12 | fgets(str, 100, stdin); 13 | printf("Length of given string is: %d", strLength(str)); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/lowercaseString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void strLowercase(char str[]) 5 | { 6 | for (int i = 0; str[i]; i++) 7 | if (str[i] >= 'A' && str[i] <= 'Z') 8 | str[i] += 32; 9 | } 10 | 11 | int main() 12 | { 13 | char str[100]; 14 | 15 | printf("Enter first string: "); 16 | fgets(str, 100, stdin); 17 | 18 | strLowercase(str); 19 | printf("\nLowercase string: %s", str); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/palindromeString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int strPalindrome(char str[]) 5 | { 6 | for (int i = 0; i < strlen(str) / 2; i++) 7 | if (str[i] != str[strlen(str) - 2 - i]) 8 | return 0; 9 | 10 | return 1; 11 | } 12 | 13 | int main() 14 | { 15 | char str[100]; 16 | 17 | printf("Enter first string: "); 18 | fgets(str, 100, stdin); 19 | 20 | if (strPalindrome(str)) 21 | printf("\nString is Palindrome!"); 22 | else 23 | printf("\nString is Not Palindrome!"); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/reverseString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void strRev(char str[]) 4 | { 5 | int strLength = strlen(str); 6 | for (int i = 0; i < strLength / 2; i++) 7 | { 8 | int temp = str[i]; 9 | str[i] = str[strLength - 2 - i]; 10 | str[strLength - 2 - i] = temp; 11 | } 12 | 13 | } 14 | int main() 15 | { 16 | char str[100]; 17 | printf("Enter string: "); 18 | fgets(str, 100, stdin); 19 | strRev(str); 20 | printf("Reverse string: %s",str); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/tempCodeRunnerFile.c: -------------------------------------------------------------------------------- 1 | trLength- -------------------------------------------------------------------------------- /C Language Assignments/C(String and Function) - Assignment-18/uppcaseString.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void strUppercase(char str[]) 5 | { 6 | for (int i = 0; str[i]; i++) 7 | if (str[i] >= 'a' && str[i] <= 'z') 8 | str[i] -= 32; 9 | } 10 | 11 | int main() 12 | { 13 | char str[100]; 14 | 15 | printf("Enter first string: "); 16 | fgets(str, 100, stdin); 17 | 18 | strUppercase(str); 19 | printf("\nUppercase string: %s", str); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Structure) - Assignment-21/defineStructure.c: -------------------------------------------------------------------------------- 1 | struct Employee 2 | { 3 | int id; 4 | char name[20]; 5 | float salary; 6 | }; -------------------------------------------------------------------------------- /C Language Assignments/C(Structure) - Assignment-21/displayEmpyeData.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct Employee 3 | { 4 | int id; 5 | float salary; 6 | char name[20]; 7 | }; 8 | void displayUserData(struct Employee user1) 9 | { 10 | printf("\nUser id - %d", user1.id); 11 | printf("\nUser name: %s", user1.name); 12 | printf("User Salary: %.2f", user1.salary); 13 | } 14 | void inputUserData(struct Employee *user1) 15 | { 16 | printf("Enter Id: "); 17 | scanf("%d", &user1->id); 18 | fflush(stdin); // because buffer is full so next fgets function not take name to we use fflush function 19 | printf("Enter User Name: "); 20 | fgets(user1->name, sizeof(user1->name), stdin); 21 | printf("Enter User salary: "); 22 | scanf("%f", &user1->salary); 23 | } 24 | int main() 25 | { 26 | struct Employee user1; 27 | inputUserData(&user1); 28 | displayUserData(user1); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Structure) - Assignment-21/displayUserData.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct Employee 3 | { 4 | int id; 5 | char name[20]; 6 | float salary; 7 | }; 8 | 9 | void displayUserData(struct Employee user1) 10 | { 11 | printf("\nUser1 Id: %d", user1.id); 12 | printf("\nUser Name: %s", user1.name); 13 | printf("User salary: %.2f", user1.salary); 14 | } 15 | 16 | void inputUserData(struct Employee *user1) 17 | { 18 | printf("Enter Id: "); 19 | scanf("%d", &user1->id); 20 | fflush(stdin); // because buffer is full so next fgets function not take name to we use fflush function 21 | printf("Enter User Name: "); 22 | fgets(user1->name, sizeof(user1->name), stdin); 23 | printf("Enter User salary: "); 24 | scanf("%f", &user1->salary); 25 | } 26 | int main() 27 | { 28 | struct Employee user1; 29 | inputUserData(&user1); 30 | displayUserData(user1); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Structure) - Assignment-21/inputEmployeeData.c: -------------------------------------------------------------------------------- 1 | #include 2 | struct Employee 3 | { 4 | int id; 5 | float salary; 6 | char name[20]; 7 | }; 8 | void inputUserData(struct Employee user1) 9 | { 10 | printf("Enter Id: "); 11 | scanf("%d", &user1.id); 12 | fflush(stdin); // because buffer is full so next fgets function not take name to we use fflush function 13 | printf("Enter User Name: "); 14 | fgets(user1.name, sizeof(user1.name), stdin); 15 | printf("Enter User salary: "); 16 | scanf("%f", &user1.salary); 17 | } 18 | int main() 19 | { 20 | struct Employee user1; 21 | inputUserData(user1); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Switch Case Problem) Assignment-9/EvenToNearOddNum.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int evenNum; 4 | printf("Enter evenNumber: "); 5 | scanf("%d",&evenNum); 6 | switch(evenNum%2) 7 | { 8 | case 0: 9 | printf("nearest odd number is: %d",evenNum+1); 10 | break; 11 | default: 12 | printf("Not a even number\nTry agian!"); 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Switch Case Problem) Assignment-9/convertIf_Else_to_switchCase.c: -------------------------------------------------------------------------------- 1 | /* 2 | if (var == 1) 3 | System.out.println("good"); 4 | else if (var == 2) 5 | System.out.println("better"); 6 | else if (var == 3) 7 | System.out.println("best"); 8 | else 9 | System.out.println("invalid"); 10 | */ 11 | #include 12 | int main() 13 | { 14 | int var; 15 | printf("Enter the value of var: "); 16 | scanf("%d", &var); 17 | switch (var) 18 | { 19 | case 1: 20 | printf("Good!"); 21 | break; 22 | case 2: 23 | printf("Better!"); 24 | break; 25 | case 3: 26 | printf("Best!"); 27 | break; 28 | default: 29 | printf("Invalid!"); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Switch Case Problem) Assignment-9/convertPosToNegAndNegToPos.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int num; 4 | printf("Enter a number: "); 5 | scanf("%d",&num); 6 | switch(num<0) 7 | { 8 | case 1: 9 | printf("Convert: Negative to Positive: %d",num*-1); 10 | break; 11 | default: 12 | printf("Convert: Positive to Negative: %d",num*-1); 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Switch Case Problem) Assignment-9/leapYearUsingSwitchCase.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int year; 5 | printf("Enter year: "); 6 | scanf("%d", &year); 7 | switch (year % 400) 8 | { 9 | case 0: 10 | printf("Yup!, it is leap year!"); 11 | break; 12 | default: 13 | switch (year % 100) 14 | { 15 | case 0: 16 | printf("Not a leap year!"); 17 | break; 18 | default: 19 | switch (year % 4) 20 | { 21 | case 0: 22 | printf("Leap year"); 23 | break; 24 | default: 25 | printf("Not a leap year!"); 26 | } 27 | } 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Switch Case Problem) Assignment-9/takeDaysDisplayMessageForTheDay.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int dayNum; 5 | printf("Enter the day number of the week: "); 6 | scanf("%d",&dayNum); 7 | switch(dayNum) 8 | { 9 | case 1: 10 | printf("Today is monday!"); 11 | break; 12 | case 2: 13 | printf("Today is Tuesday!"); 14 | break; 15 | case 3: 16 | printf("Today is Wednesday!"); 17 | break; 18 | case 4: 19 | printf("Today is Thursday!"); 20 | break; 21 | case 5: 22 | printf("Today is Friday!"); 23 | break; 24 | case 6: 25 | printf("Today is Saturday!"); 26 | break; 27 | case 7: 28 | printf("Today is Sunday!"); 29 | break; 30 | default: 31 | printf("Invalid week number!"); 32 | 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Switch Case Problem) Assignment-9/takeMonthNumDisplayDays.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int monthNum; 5 | printf("Enter month number: "); 6 | scanf("%d",&monthNum); 7 | switch(monthNum) 8 | { 9 | case 1: 10 | case 3: 11 | case 5: 12 | case 7: 13 | case 8: 14 | case 10: 15 | case 12: 16 | printf("31 Days!"); 17 | break; 18 | case 4: 19 | case 6: 20 | case 9: 21 | case 11: 22 | printf("30 Days!"); 23 | break; 24 | case 2: 25 | printf("28 or 29 days depont upon year is leap year or not"); 26 | break; 27 | default: 28 | printf("wrong value!"); 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C Language Assignments/C(Switch Case Problem) Assignment-9/totalElectricityBill.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int unit; 5 | printf("Enter the total eletricity consume -"); 6 | scanf("%d", &unit); 7 | float totalBill, sucharge; 8 | switch (unit) 9 | { 10 | case 1 ... 50: 11 | totalBill = unit * 0.50; 12 | break; 13 | case 51 ... 150: 14 | totalBill = 25 + ((unit - 50) * 0.75); 15 | break; 16 | case 151 ... 250: 17 | totalBill = 100 + ((unit - 150) * 1.20); 18 | break; 19 | default: 20 | totalBill = 220 + ((unit - 250) * 1.50); 21 | } 22 | sucharge = totalBill * 0.20; 23 | printf("Total bill is: %.2f", totalBill + sucharge); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/HelloNewLineMySirG.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 2. Write a C++ program to print Hello on the first line and MySirG on the second line 3 | using endl. 4 | */ 5 | #include 6 | int main() 7 | { 8 | std::cout<<"Hello "< 5 | using namespace std; 6 | int main() 7 | { 8 | int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 9 | int sum = 0; 10 | for (int i = 0; i < 10; i++) 11 | sum += arr[i]; 12 | cout << "Sum of all element is: " << sum; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/areaOfCircle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 4. Write a C++ program to calculate the area of a circle 3 | */ 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | float radius = 5.4f; 9 | float areaOfCircle = 3.14 * radius * radius; 10 | cout << "Area of Circle is: " << areaOfCircle << " having radius " << radius; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/averageOfThreeNum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 6. Write a C++ program to calculate an average of 3 numbers. 3 | */ 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int num1 = 5, num2 = 4, num3 = 8; 9 | cout << "Average of three numbers is: " << (num1 + num2 + num3) / 3.0f; 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/maxOfTwoNum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 9. Write a C++ program to find the maximum of two numbers. 3 | */ 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int num1 = 43, num2 = 6; 9 | cout << "Max of " << num1 << " and " << num2 << " is: " << (num1 > num2 ? num1 : num2); 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/printHelloMySirG.cpp: -------------------------------------------------------------------------------- 1 | // 1. Write a C++ program to print Hello MySirG on the screen. 2 | #include 3 | int main() 4 | { 5 | std::cout<<"Hello MySirG"; 6 | return 0; 7 | } -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/squareOfNumber.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 7. Write a C++ program to calculate the square of a number 3 | */ 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int num1 = 5; 9 | cout << "Square of " << num1 << " is: " << num1 * num1; 10 | return 0; 11 | } -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/sumOfTwoNum.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3. Write a C++ program to calculate the sum of two numbers. 3 | */ 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int num1 = 5, num2 = 6; 9 | int sum = num1 + num2; 10 | cout << "Sum of " << num1 << " and " << num2 << " is " << sum; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/swapValueWithoutUsingThirdVar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 8. Write a C++ program to swap values of two int variables without using third variable 3 | */ 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int num1 = 5, num2 = 3; 9 | cout << "Before Swapping, a = " << num1 << " b = " << num2 << endl; 10 | num1 = num1 + num2; // 8 11 | num2 = num1 - num2; // 3 12 | num1 = num1 - num2; // 5 13 | cout << "After Swapping, a = " << num1 << " b = " << num2 << endl; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /C++ Language Assignments/Basic of C++ - Assignment - 23/volumeOfCubiod.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 5. Write a C++ program to calculate the volume of a cuboid. 3 | */ 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int length = 3, breadth = 4, height = 5; 9 | int volumeOfCubiod = length * breadth * height; 10 | cout << "Volume of Cubiod is: " << volumeOfCubiod << "m3, having length: " << length << " breath: " << breadth << " height: " << height; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complext 4 | { 5 | private: 6 | int real, img; 7 | 8 | public: 9 | void setValue(int x, int y) 10 | { 11 | real = x; 12 | img = y; 13 | } 14 | void showValue() 15 | { 16 | cout << "Complext number: " << real << "+" << img << "i"; 17 | } 18 | }; 19 | int main() 20 | { 21 | Complext c; 22 | c.setValue(5, 4); 23 | c.showValue(); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-02.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Time 4 | { 5 | private: 6 | int hrs, min, sec; 7 | 8 | public: 9 | void setTime(int h, int m, int s) 10 | { 11 | hrs = h; 12 | min = m; 13 | sec = s; 14 | } 15 | void showTime() 16 | { 17 | cout << "Time: " << hrs << " Hours " << min << " Minute " << sec << " Second "; 18 | } 19 | }; 20 | int main() 21 | { 22 | Time t; 23 | t.setTime(5, 44, 34); 24 | t.showTime(); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-03.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Factorial 4 | { 5 | public: 6 | int findFactorial(int f) 7 | { 8 | int fact = 1; 9 | for (int i = 2; i <= f; i++) 10 | fact = fact * i; 11 | return fact; 12 | } 13 | }; 14 | int main() 15 | { 16 | Factorial f; 17 | int x; 18 | cout << "Enter a numebr: "; 19 | cin >> x; 20 | cout << "Factorial is: " << f.findFactorial(x); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-04.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class LargestNumber 4 | { 5 | public: 6 | int largeNumberAmongThree(int x, int y, int z) 7 | { 8 | return x > y && x > z ? x : y > z ? y 9 | : z; 10 | } 11 | }; 12 | int main() 13 | { 14 | LargestNumber l; 15 | int num1, num2, num3; 16 | cout << "Enter a three number: "; 17 | cin >> num1 >> num2 >> num3; 18 | int largestNumber = l.largeNumberAmongThree(num1, num2, num3); 19 | cout << "Largest Number is: " << largestNumber << endl; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-06.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Square 4 | { 5 | public: 6 | int findSquare(int num) 7 | { 8 | static int countFunctionCalling; 9 | countFunctionCalling++; // oops we no need to initialize 0 coz static variable by default ini.. 0 10 | cout << countFunctionCalling << " Time Calling this function--!" << endl; 11 | return num * num; 12 | } 13 | }; 14 | int main() 15 | { 16 | Square s; 17 | s.findSquare(6); 18 | s.findSquare(5); 19 | s.findSquare(6); 20 | s.findSquare(5); 21 | s.findSquare(6); 22 | s.findSquare(5); 23 | s.findSquare(6); 24 | s.findSquare(5); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-07.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Greatest 4 | { 5 | public: 6 | int largeNumberAmongThree(int x, int y, int z) 7 | { 8 | return x > y && x > z ? x : y > z ? y 9 | : z; 10 | } 11 | }; 12 | int main() 13 | { 14 | Greatest g; 15 | int num1, num2, num3; 16 | cout << "Enter a three number: "; 17 | cin >> num1 >> num2 >> num3; 18 | int largestNumber = g.largeNumberAmongThree(num1, num2, num3); 19 | cout << "Largest Number is: " << largestNumber << endl; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-08.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Rectangle 4 | { 5 | public: 6 | int findRectangleArea(int b, int h) 7 | { 8 | return b * h; 9 | } 10 | }; 11 | int main() 12 | { 13 | Rectangle r; 14 | cout << "Rectangle of Area is: " << r.findRectangleArea(5, 4); 15 | return 0; 16 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Classes and Object) - Assignment - 25/Question-09.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Circle 4 | { 5 | public: 6 | double findCircleArea(float r) 7 | { 8 | return 3.14 * r * r; 9 | } 10 | }; 11 | int main() 12 | { 13 | Circle c; 14 | float radius; 15 | cout << "Enter a radius: "; 16 | cin >> radius; 17 | cout << "Rectangle of Area is: " < 2 | using namespace std; 3 | class Area 4 | { 5 | public: 6 | double areaOfCircle(float r) 7 | { 8 | return 3.14 * r * r; 9 | } 10 | int areaOfRectangle(int b, int h) 11 | { 12 | return b * h; 13 | } 14 | int areaOfSquare(int a) 15 | { 16 | return a * a; 17 | } 18 | }; 19 | int main() 20 | { 21 | Area a; 22 | cout << "Area of circle for radius 5 is: " << a.areaOfCircle(5) << endl; 23 | cout << "Area of rectangle having 5 breath and 5 height is: " << a.areaOfRectangle(5, 5) << endl; 24 | cout << "Area of square having 5 sides is: " << a.areaOfSquare(5) << endl; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Exception Handling) - Assignment-30/Problem1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void test_try(int num) 4 | { 5 | try 6 | { 7 | if (num >= 0 && num <= 9) 8 | throw num; 9 | else 10 | cout << "\nIt is not a Single Number\n"; 11 | throw; 12 | } 13 | catch (int a) 14 | { 15 | cout << "\nIt is a Single Number\n"; 16 | } 17 | catch (char b[100]) 18 | { 19 | cout << b << endl; 20 | } 21 | } 22 | int main() 23 | { 24 | int num; 25 | cout << "Enter a number: "; 26 | cin >> num; 27 | test_try(num); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Exception Handling) - Assignment-30/Problem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | try 6 | { 7 | throw 'E'; 8 | } 9 | catch (char e) 10 | { 11 | cout << "\nException Caught " << e << " " << endl; 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Exception Handling) - Assignment-30/Problem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool isEmailValid(string email) 4 | { 5 | int atFlag = -1, dotFlag = -1; 6 | int length = 0; 7 | for (int i = 0; email[i] != '\0'; i++) 8 | { 9 | if (email[i] == '@') 10 | atFlag = i; 11 | if (email[i] == '.') 12 | dotFlag = i; 13 | length++; 14 | } 15 | if (atFlag == -1 && dotFlag == -1) 16 | return 0; 17 | else if (atFlag > dotFlag) 18 | return 0; 19 | else 20 | return 1; 21 | } 22 | int main() 23 | { 24 | string email; 25 | cout << "Enter Email Id: "; 26 | cin >> email; 27 | try 28 | { 29 | if (isEmailValid(email)) 30 | cout << "Email is valid.."; 31 | else 32 | throw 'c'; 33 | } 34 | catch (const char e) 35 | { 36 | cout << "\nException caught...!, Invalid email id..!"; 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Exception Handling) - Assignment-30/Problem5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | bool isValidNumber(string m) 5 | { 6 | int i; 7 | for (i = 0; m[i] != '\0'; i++) 8 | ; 9 | if (i == 10) 10 | return true; 11 | return false; 12 | } 13 | int main() 14 | { 15 | string mobileNum; 16 | cout<<"Enter Mobile Number: "; 17 | cin >> mobileNum; 18 | try 19 | { 20 | if (isValidNumber(mobileNum)) 21 | cout << "\nValid Mobile Number..." << endl; 22 | else 23 | throw 1; 24 | } 25 | catch (int n) 26 | { 27 | cout << "\nException Caught...\n Invalid Mobile Number" << endl; 28 | } 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Exception Handling) - Assignment-30/Problem6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | bool isValidPinCode(string m) 5 | { 6 | int i; 7 | for (i = 0; m[i] != '\0'; i++) 8 | { 9 | if (!(m[i] >= '0' && m[i] <= '9')) 10 | return false; 11 | } 12 | 13 | if (i == 6) 14 | return true; 15 | return false; 16 | } 17 | int main() 18 | { 19 | string pinCode; 20 | cout << "Enter Area Pincode: "; 21 | cin >> pinCode; 22 | try 23 | { 24 | if (isValidPinCode(pinCode)) 25 | cout << "\nValid area pincode..." << endl; 26 | else 27 | throw 1; 28 | } 29 | catch (int n) 30 | { 31 | cout << "\nException Caught...\n Invalid area pincode" << endl; 32 | } 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Exception Handling) - Assignment-30/Problem9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool isValidGamilId(string gmailId) 4 | { 5 | int atContain = -1, gmailContain = -1; 6 | int i; 7 | if (gmailId.find("@gmail.com") != -1) // this funtion find substring in gmaild 8 | return true; 9 | return false; 10 | } 11 | int main() 12 | { 13 | string gmailId; 14 | cout << "Enter Gemail Id - "; 15 | cin >> gmailId; 16 | try 17 | { 18 | if (isValidGamilId(gmailId)) 19 | cout << "\nValid gmail id.."; 20 | else 21 | throw 'e'; 22 | } 23 | catch (char e) 24 | { 25 | cout << "\nException occurr... " << e << " \nInvalid gmaild id"; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(File Handling) - Assignment - 34/Problem1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | ofstream fout; 7 | fout.open("D:/My Life/hello.txt"); 8 | if (fout) 9 | { 10 | cout << "File Open.."; 11 | fout << "Hello World"; 12 | } 13 | else 14 | cout << "File not opend..."; 15 | fout.close(); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(File Handling) - Assignment - 34/Problem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | // firstly file created 7 | ofstream fout; 8 | fout.open("D:/My Life/read.txt"); 9 | fout << "Hello world"; 10 | fout.close(); 11 | 12 | // file read 13 | ifstream fin; 14 | fin.open("D:/My Life/read.txt"); 15 | fin.seekg(0, ios_base::beg); // file pointer go to starting position 16 | char ch; 17 | int i, countChar = 0, countSpace = 0; 18 | while (!fin.eof()) 19 | { 20 | fin.get(ch); 21 | if ((ch >= 65 && ch <= 91) || (ch >= 97 && ch <= 122)) 22 | countChar++; 23 | else if (ch == ' ') 24 | countSpace++; 25 | } 26 | cout << "\nNo. of character in a file: " << countChar << endl; 27 | cout << "\nNo. of space between these words: " << countSpace+1 << endl; 28 | fin.close(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(File Handling) - Assignment - 34/Problem3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | ofstream fout; 7 | fout.open("D:/My Life/read.txt", ios::app); 8 | if (fout.is_open()) 9 | fout << "Append some extra words"; // add these words in a file 10 | else 11 | cout << "File not open.."; 12 | fout.close(); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(File Handling) - Assignment - 34/Problem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ifstream fin; 8 | ofstream fout; 9 | 10 | fout.open("D:/My Life/first.txt"); 11 | fout << "This is first file content"; 12 | fout.close(); 13 | 14 | fin.open("D:/My Life/first.txt"); 15 | fout.open("D:/My Life/second.txt"); 16 | 17 | char ch; 18 | while (!fin.eof()) 19 | { 20 | fin.get(ch); // you can use getline(fin, str) function 21 | if (ch >= 65 and ch <= 91) 22 | fout << tolower(ch); 23 | else if (ch >= 97 and ch <= 122) 24 | fout << toupper(ch); 25 | } 26 | 27 | fin.close(); 28 | fout.close(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(File Handling) - Assignment - 34/Problem5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | ifstream fin1, fin2; 8 | ofstream fout; 9 | 10 | fin1.open("D:/My Life/first.txt"); 11 | fin2.open("D:/My Life/second.txt"); 12 | fout.open("D:/My Life/mergeFile.txt"); 13 | 14 | // you can also check file opened or not 15 | char ch; 16 | while (!fin1.eof()) 17 | { 18 | fin1.get(ch); // you can use getline(fin, str) function 19 | fout << ch; 20 | } 21 | while (!fin2.eof()) 22 | { 23 | fin2.get(ch); // you can use getline(fin, str) function 24 | fout << ch; 25 | } 26 | fin1.close(); 27 | fin2.close(); 28 | fout.close(); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(File Handling) - Assignment - 34/Problem6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | ifstream fin; 7 | fin.open("D:/My Life/mergeFile.txt"); 8 | if (fin.is_open()) 9 | { 10 | int noOfLine = 0, noOfChar = 0, noOfWords = 0; 11 | while (!fin.eof()) 12 | { 13 | string str; 14 | getline(fin, str); 15 | noOfLine++; 16 | for (int i = 0; i < str.size(); i++) 17 | { 18 | if (str[i] == ' ') 19 | noOfWords++; 20 | else 21 | noOfChar++; 22 | } 23 | } 24 | cout << "\nIn file,\nNo. of line is: " << noOfLine << endl; 25 | cout << "\nNo. of character is: " << noOfChar << endl; 26 | cout << "\nNo. of words is: " << noOfWords +1<< endl; 27 | } 28 | else 29 | { 30 | cout << "File not open.."; 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/areaFunctionOverloading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | float area(int r) 4 | { 5 | return 3.14 * r * r; 6 | } 7 | float area(int w, int h) 8 | { 9 | return w * h; 10 | } 11 | float area(double b, double h) 12 | { 13 | return ((b * h) / 2.0); 14 | } 15 | int main() 16 | { 17 | cout << "Area of Circle: " << area(5) << ", having " << 5 << " radius" << endl; 18 | cout << "Area of Rectangle " << area(3, 4) << ", having " << 3 << " width and " << 4 << " height" << endl; 19 | cout << "Area of Trinalge " << area(3.5, 4.3)<< ", having " << 3 << " breadth and " << 4 << " height" << endl;; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/checkFibonacciSeriesNum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool checkFibonacciSeriesNum(int num) 4 | { 5 | if (num == 0 || num == 1) 6 | return true; 7 | else 8 | { 9 | int x = 0, y = 1, temp; 10 | while (x + y <= num) 11 | { 12 | if (x + y == num) 13 | return true; 14 | temp = x + y; 15 | x = y; 16 | y = temp; 17 | } 18 | } 19 | return false; 20 | } 21 | int main() 22 | { 23 | int num; 24 | cout << "Enter a number: "; 25 | cin >> num; 26 | if (checkFibonacciSeriesNum(num)) 27 | cout << num << " is present in fibonacci series!"; 28 | else 29 | cout << num << " is not present in fibonacci series!"; 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/defaultArgumentFunction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int add(int num1, int num2, int num3 = 0); // this function able to add too argument or three argument number 4 | int main() 5 | { 6 | int num1, num2, num3; 7 | cout << "Enter two number: "; 8 | cin >> num1 >> num2; 9 | cout << "Sum of " << num1 << " and " << num2 << " is: " << add(num1, num2) << endl; 10 | cout << "\nNow enter three number: "; 11 | cin >> num1 >> num2 >> num3; 12 | cout << "Sum of " << num1 << ", " << num2 << " and " << num3 << " is: " << add(num1, num2, num3) << endl; 13 | return 0; 14 | } 15 | int add(int num1, int num2, int num3) 16 | { 17 | return num1 + num2 + num3; 18 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/heighestValueDigit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int heighestValueDigit(int digit) 4 | { 5 | int maxDigit = -1; 6 | while (digit != 0) 7 | { 8 | if (maxDigit < digit % 10) 9 | maxDigit = digit % 10; 10 | digit /= 10; 11 | } 12 | 13 | return maxDigit; 14 | } 15 | int main() 16 | { 17 | cout << heighestValueDigit(572); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/maxNumFunctionOverLoading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int maxNumber(int num1, int num2) 3 | { 4 | return num1 > num2 ? num1 : num2; 5 | } 6 | float maxNumber(float num1, float num2) 7 | { 8 | return num1 > num2 ? num1 : num2; 9 | } 10 | using namespace std; 11 | int main() 12 | { 13 | float num1, num2; 14 | cout << "Enter two int type number: "; 15 | cin >> num1 >> num2; 16 | cout << "Max number is: " << maxNumber((int)num1, (int)num2) << endl; // not need to make two extra int variable 17 | cout << "Enter two float type number: "; 18 | cin >> num1 >> num2; 19 | cout << "Max number is: " << maxNumber(num1, num2) << endl; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/pascalTriangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int fact(int n) 5 | { 6 | int ans = 1; 7 | for (int i = 2; i <= n; i++) 8 | ans = ans * i; 9 | return ans; 10 | } 11 | 12 | int nCr(int n, int r) 13 | { 14 | return (fact(n) / fact(n - r) / fact(r)); 15 | } 16 | 17 | void pascalTriangle(int lines) 18 | { 19 | for (int i = 1; i <= lines; i++) 20 | { 21 | int k = 1, col = 0; 22 | for (int j = 1; j < lines * 2; j++) 23 | { 24 | if (j >= (lines + 1) - i && j <= (lines - 1) + i && k) 25 | { 26 | cout << nCr(i - 1, col) << " "; 27 | col++; 28 | k = 0; 29 | } 30 | else 31 | { 32 | cout << " "; 33 | k = 1; 34 | } 35 | } 36 | cout << endl; 37 | } 38 | } 39 | int main() 40 | { 41 | pascalTriangle(5); 42 | return 0; 43 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/power.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int power(int x, int y) 4 | { 5 | int ans = 1; 6 | for (int i = 1; i <= y; i++) 7 | ans *= x; 8 | 9 | return ans; 10 | } 11 | int main() 12 | { 13 | cout << power(5, 5); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/primeNumOrNot.cpp: -------------------------------------------------------------------------------- 1 | int primeNum(int n) 2 | { 3 | bool flag = false; 4 | for (int i = 2; i <= n / 2; i++) 5 | { 6 | if (n % i == 0) 7 | { 8 | flag = true; 9 | break; 10 | } 11 | } 12 | 13 | if(flag) 14 | return 1; // primeNo. 15 | else 16 | return 0; // noPrimeNo. 17 | 18 | // if(flag) 19 | // cout<<"Prime Number!"; 20 | // else 21 | // cout<<"Not Prime Number!"; 22 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Functions) - Assignment - 24/swapDataUsingCallByReference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void swap(int &, int &); 4 | int main() 5 | { 6 | int num1, num2; 7 | cout << "Enter two number: "; 8 | cin >> num1 >> num2; 9 | cout << "\nBefore swaping: "; 10 | cout << "Num1 = " << num1 << " and Num2 = " << num2 << endl; 11 | swap(num1, num2); 12 | cout << "\nAfter swaping: "; 13 | cout << "Num1 = " << num1 << " and Num2 = " << num2 << endl; 14 | 15 | return 0; 16 | } 17 | void swap(int &x, int &y) 18 | { 19 | int temp = x; 20 | x = y; 21 | y = temp; 22 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Member Function, Static and Constructor) - Assignment-26/Question-01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | private: 6 | int real, img; 7 | 8 | public: 9 | void setData(int x, int y) 10 | { 11 | real = x; 12 | img = y; 13 | } 14 | void showData() 15 | { 16 | cout << "Real = " << real << " img = " << img << endl; 17 | } 18 | Complex add(Complex C) 19 | { 20 | Complex temp; 21 | temp.real = real + C.real; 22 | temp.img = img + C.img; 23 | return temp; 24 | } 25 | }; 26 | int main() 27 | { 28 | Complex c1, c2, c3; 29 | c1.setData(1, 2); 30 | c2.setData(3, 4); 31 | c1.showData(); 32 | c2.showData(); 33 | c3 = c1.add(c2); 34 | c3.showData(); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Member Function, Static and Constructor) - Assignment-26/Question-03.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Cube 4 | { 5 | private: 6 | int a; 7 | 8 | public: 9 | Cube(int x) 10 | { 11 | a = x; 12 | } 13 | int showCubeVolume() 14 | { 15 | return a * a * a; 16 | } 17 | }; 18 | int main() 19 | { 20 | Cube c1(5); 21 | cout << "Volmue of cube is " << c1.showCubeVolume(); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Member Function, Static and Constructor) - Assignment-26/Question-05.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Date 4 | { 5 | private: 6 | int dd, mm, yy; 7 | 8 | public: 9 | Date(int x, int y, int z) 10 | { 11 | dd = x; 12 | mm = y; 13 | yy = z; 14 | } 15 | void displayDate() 16 | { 17 | cout << "DD = " << dd << ", MM = " << mm << ", YY = " << yy << endl; 18 | } 19 | }; 20 | int main() 21 | { 22 | Date d(10,9,2022); 23 | d.displayDate(); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Member Function, Static and Constructor) - Assignment-26/Question-06.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Student 5 | { 6 | private: 7 | int rollNo, age; 8 | long int mobileNo; 9 | char name[20]; 10 | 11 | public: 12 | Student(int x, char studentName[], int y, int z) 13 | { 14 | rollNo = x; 15 | strcpy(name, studentName); 16 | age = y; 17 | mobileNo = z; 18 | } 19 | void displayStudentData() 20 | { 21 | cout << "Roll No. - " << rollNo << ", Name - " << name << ", Age - " << age << ", Mobile No. - " << mobileNo << endl; 22 | } 23 | }; 24 | int main() 25 | { 26 | Student st(12, "Ajay", 19, 1234567890); 27 | st.displayStudentData(); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Member Function, Static and Constructor) - Assignment-26/Question-07.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Box 4 | { 5 | private: 6 | int length, breath, height; 7 | 8 | public: 9 | Box(int x, int y, int z) 10 | { 11 | length = x; 12 | breath = y; 13 | height = z; 14 | } 15 | int volOfBox() 16 | { 17 | return length * breath * height; 18 | } 19 | }; 20 | int main() 21 | { 22 | Box b(1, 2, 3); 23 | cout << "Volume of Box is: " << b.volOfBox() << endl; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Member Function, Static and Constructor) - Assignment-26/Question-08.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Bank 4 | { 5 | private: 6 | int principal, roi, year; 7 | 8 | public: 9 | Bank(int x, int y, int z) 10 | { 11 | principal = x; 12 | roi = y; 13 | year = z; 14 | } 15 | int simpleIntrest() 16 | { 17 | return (principal * roi * year) / 100; 18 | } 19 | }; 20 | int main() 21 | { 22 | Bank b(1000, 2, 3); 23 | cout << "simple intrest is: $" << b.simpleIntrest() << endl; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Member Function, Static and Constructor) - Assignment-26/Question-10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class StaticCount 4 | { 5 | private: 6 | static int count; 7 | 8 | public: 9 | static int fun() 10 | { 11 | count++; 12 | } 13 | static int getCount() 14 | { 15 | return count; 16 | } 17 | }; 18 | int StaticCount::count = 0; 19 | int main() 20 | { 21 | StaticCount::fun(); 22 | StaticCount::fun(); 23 | StaticCount::fun(); 24 | StaticCount::fun(); 25 | cout << "Calling times: " << StaticCount::getCount(); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(New, Delete and Inheritance) - Assignment - 31/Problem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Base 4 | { 5 | private: 6 | float x, y; 7 | 8 | public: 9 | void acceptData() 10 | { 11 | cout << "Enter First Number: "; 12 | cin >> x; 13 | cout << "Enter Second Number: "; 14 | cin >> y; 15 | } 16 | 17 | protected: 18 | float getX() { return x; } 19 | float getY() { return y; } 20 | }; 21 | class Derived : public Base // single inheritance 22 | { 23 | private: 24 | float sum; 25 | 26 | public: 27 | void doSum() 28 | { 29 | sum = getX() + getY(); 30 | } 31 | float getSum() { return sum; } 32 | }; 33 | int main() 34 | { 35 | Derived obj; 36 | obj.acceptData(); 37 | obj.doSum(); 38 | cout << obj.getSum() << endl; 39 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(New, Delete and Inheritance) - Assignment - 31/Problem6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class B; 4 | class A 5 | { 6 | protected: 7 | int x; 8 | 9 | public: 10 | void setX(int x) { this->x = x; } 11 | void showX() { cout << "X = " << x << endl; } 12 | friend void swap(A &, B &); 13 | }; 14 | class B 15 | { 16 | protected: 17 | int y; 18 | 19 | public: 20 | void setY(int y) { this->y = y; } 21 | void showY() { cout << "Y = " << y << endl; } 22 | friend void swap(A &, B &); 23 | }; 24 | void swap(A &a, B &b) 25 | { 26 | int temp = a.x; 27 | a.x = b.y; 28 | b.y = temp; 29 | } 30 | int main() 31 | { 32 | A a; 33 | B b; 34 | a.setX(5); 35 | b.setY(4); 36 | cout << "\nBefore swapping: "; 37 | a.showX(); 38 | b.showY(); 39 | swap(a, b); 40 | cout << "\nAfter swapping: "; 41 | a.showX(); 42 | b.showY(); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading and friend function) - Assignment - 27/Question-03.cpp: -------------------------------------------------------------------------------- 1 | // 3. Write a C++ program to add two complex numbers using operator overloaded by a 2 | // friend function. 3 | #include 4 | using namespace std; 5 | class Complex 6 | { 7 | private: 8 | int real, img; 9 | 10 | public: 11 | void setData(int x, int y) 12 | { 13 | real = x; 14 | img = y; 15 | } 16 | void showData() 17 | { 18 | cout << real << " + " << img << " i" << endl; 19 | } 20 | friend Complex operator+(Complex, Complex); 21 | }; 22 | 23 | Complex operator+(Complex x, Complex y) 24 | { 25 | Complex temp; 26 | temp.real = x.real + y.real; 27 | temp.img = x.img + y.img; 28 | return temp; 29 | } 30 | 31 | int main() 32 | { 33 | Complex c1, c2, c3; 34 | c1.setData(5, 4); 35 | c2.setData(6, 7); 36 | c1.showData(); 37 | c2.showData(); 38 | c3 = c1 + c2; // operator+(c1,c2); 39 | c3.showData(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | private: 6 | int real, img; 7 | 8 | public: 9 | Complex(int x, int y) 10 | { 11 | real = x; 12 | img = y; 13 | } 14 | Complex() {} 15 | friend ostream &operator<<(ostream &output, Complex c); 16 | friend istream &operator>>(istream &input, Complex c); 17 | }; 18 | ostream &operator<<(ostream &output, Complex c) 19 | { 20 | output << "Real = " << c.real << " Imag = " << c.img << endl; 21 | return output; 22 | } 23 | istream &operator>>(istream &input, Complex c) 24 | { 25 | input >> c.real >> c.img; 26 | return input; 27 | } 28 | int main() 29 | { 30 | Complex c1(2, 3), c2(4, 4); 31 | cout << c1 << c2; 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Distance 4 | { 5 | private: 6 | int feet, inches; 7 | 8 | public: 9 | Distance() {} 10 | Distance(int f, int i) 11 | { 12 | feet = f; 13 | inches = i; 14 | } 15 | void operator()(int a, int b, int c) 16 | { 17 | feet = a + c + 5; 18 | inches = a + b + 15; 19 | } 20 | void display() { cout << "Feet = " << feet << " Inches = " << inches << endl; } 21 | }; 22 | int main() 23 | { 24 | Distance d1(4,3), d2, d3; 25 | d1(2,3,4); 26 | d1.display(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Marks 4 | { 5 | private: 6 | int marks; 7 | 8 | public: 9 | Marks() {} 10 | Marks(int x) { marks = x; } 11 | void printMarks() { cout << "Marks: " << marks << endl; } 12 | Marks *operator->() 13 | { 14 | return this; 15 | } 16 | }; 17 | 18 | int main() 19 | { 20 | Marks m1(55), m2; 21 | m1->printMarks(); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | private: 6 | int real, img; 7 | 8 | public: 9 | Complex(int x, int y) 10 | { 11 | real = x; 12 | img = y; 13 | } 14 | Complex() {} 15 | void setData(int real, int img) 16 | { 17 | this->real = real; 18 | this->img = img; 19 | } 20 | friend ostream &operator<<(ostream &output, Complex c); 21 | friend istream &operator>>(istream &input, Complex c); 22 | }; 23 | ostream &operator<<(ostream &output, Complex c) 24 | { 25 | output << "Real = " << c.real << " Imag = " << c.img << endl; 26 | return output; 27 | } 28 | istream &operator>>(istream &input, Complex c) 29 | { 30 | input >> c.real >> c.img; 31 | return input; 32 | } 33 | int main() 34 | { 35 | Complex c1, c2; 36 | c1.setData(3, 4); 37 | c2.setData(5, 3); 38 | cout << c1 << c2; 39 | return 0; 40 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | private: 6 | int real, img; 7 | 8 | public: 9 | Complex() {} 10 | Complex(int x, int y) 11 | { 12 | real = x; 13 | img = y; 14 | } 15 | void display() { cout << "Real = " << real << " Imag = " << img << endl; } 16 | Complex operator=(Complex c) 17 | { 18 | // if we crete dma memory then first free this memory 19 | // but first check both the object are not equal 20 | // third point is c1=c2=c3 21 | // here we don't need to check this all condition because we don't cretae dma memory 22 | this->real = c.real; 23 | this->img = c.img; 24 | return *this; 25 | } 26 | }; 27 | int main() 28 | { 29 | Complex c1(5, 4), c2(5, 3); 30 | c1 = c2; 31 | c1.display(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Integer 4 | { 5 | private: 6 | int i; 7 | 8 | public: 9 | Integer(int i) : i(i) {} 10 | int operator!() 11 | { 12 | return -i; // return !i; 13 | } 14 | }; 15 | int main() 16 | { 17 | Integer x(5); // x = 5(PC constructor called ) 18 | cout << !x << endl; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Coordinate 4 | { 5 | private: 6 | int x, y, z; 7 | 8 | public: 9 | Coordinate() {} 10 | Coordinate(int x, int y, int z) 11 | { 12 | this->x = x; 13 | this->y = y; 14 | this->z = z; 15 | } 16 | void display() { cout << "x = " << x << " y = " << y << " z = " << z << endl; } 17 | Coordinate operator,(Coordinate &c) 18 | { 19 | Coordinate temp; 20 | temp.x = c.x; 21 | temp.y = c.y; 22 | temp.z = c.z; 23 | return temp; 24 | } 25 | }; 26 | int main() 27 | { 28 | Coordinate c1(4, 3, 5), c2(3, 5, 3), c3, c4(5, 3, 3); 29 | c3 = (c1, c2); 30 | c3.display(); 31 | c3 = (c1, c2, c4); 32 | c3.display(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Operator overloading, Friend function and this pointer) - Assignment-28/Problem9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Integer 4 | { 5 | private: 6 | int x; 7 | 8 | public: 9 | Integer() {} 10 | Integer(int x) { this->x = x; } 11 | operator int() 12 | { 13 | return x; 14 | } 15 | }; 16 | int main() 17 | { 18 | Integer i1(5); 19 | int x = i1; 20 | cout << "Value of x = " << x << endl; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Overriding, Overloading, Constructor in Inheritance) - Assignment - 32/Problem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Rectangle 4 | { 5 | private: 6 | double x, y; 7 | public: 8 | double area(int x, int y) 9 | { 10 | return x * y; 11 | } 12 | double area(double x, double y) // both for float and double 13 | { 14 | return x * y; 15 | } 16 | double area(int x, double y) 17 | { 18 | return x * y; 19 | } 20 | double area(double x, int y) 21 | { 22 | return x * y; 23 | } 24 | }; 25 | int main() 26 | { 27 | Rectangle r; 28 | cout< 2 | using namespace std; 3 | class Animal 4 | { 5 | private: 6 | string sound; 7 | 8 | public: 9 | string Sound() { return sound; } 10 | void setSound(string sound) { this->sound = sound; } 11 | }; 12 | class Dog : public Animal 13 | { 14 | private: 15 | string dogSound; 16 | 17 | public: 18 | string Sound() { return dogSound; } 19 | void setSound(string dogSound) { this->dogSound = dogSound; } 20 | }; 21 | int main() 22 | { 23 | Animal cat; 24 | cat.setSound("Meyow"); 25 | cout << "\nCat sound is: " << cat.Sound(); 26 | 27 | Dog petDog; 28 | petDog.setSound("Bhauu"); 29 | cout << "\nPet Dog sound is: " << petDog.Sound(); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Overriding, Overloading, Constructor in Inheritance) - Assignment - 32/Problem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Addition 4 | { 5 | private: 6 | double sum; 7 | 8 | public: 9 | void add(int x, int y) { sum = x + y; } 10 | void add(double x, double y) { sum = x + y; } 11 | void add(int x, int y, int z) { sum = x + y + z; } 12 | void add(double x, double y, double z) { sum = x + y + z; } 13 | void showSum() { cout << "\nSum is: " << sum; } 14 | }; 15 | int main() 16 | { 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Overriding, Overloading, Constructor in Inheritance) - Assignment - 32/Problem5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Person 4 | { 5 | protected: 6 | string name; 7 | int age; 8 | 9 | public: 10 | Person() {} 11 | Person(string name, int age) 12 | { 13 | this->name = name; 14 | this->age = age; 15 | } 16 | }; 17 | class Student : public Person 18 | { 19 | private: 20 | int rank; 21 | 22 | public: 23 | Student() : Person() {} 24 | Student(int rank, string name, int age) : Person(name, age) 25 | { 26 | this->rank = rank; 27 | } 28 | void showData() 29 | { 30 | cout << "\nStudent Name: " << name << " Age: " << age << " Rank: " << rank; 31 | } 32 | }; 33 | int main() 34 | { 35 | Student s(1, "Ajay Soni", 19); 36 | s.showData(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Overriding, Overloading, Constructor in Inheritance) - Assignment - 32/Problem7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Person 4 | { 5 | protected: 6 | string name; 7 | int age; 8 | 9 | public: 10 | Person() {} 11 | Person(string name, int age) 12 | { 13 | this->name = name; 14 | this->age = age; 15 | } 16 | }; 17 | class Student : public Person 18 | { 19 | private: 20 | int rank; 21 | 22 | public: 23 | Student() : Person() {} 24 | Student(int rank, string name, int age) : Person(name, age) 25 | { 26 | this->rank = rank; 27 | } 28 | void showData() 29 | { 30 | cout << "\nStudent Name: " << name << " Age: " << age << " Rank: " << rank; 31 | } 32 | }; 33 | int main() 34 | { 35 | Student s(1, "Ajay Soni", 19); 36 | s.showData(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Overriding, Overloading, Constructor in Inheritance) - Assignment - 32/Problem8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Factorial 4 | { 5 | private: 6 | int n, fact; 7 | 8 | public: 9 | Factorial(int x) 10 | { 11 | n = x; 12 | fact = 1; 13 | } 14 | Factorial(Factorial &f) 15 | { 16 | n = f.n; 17 | fact = 1; 18 | } 19 | void calculate() 20 | { 21 | for (int i = 1; i <= n; i++) 22 | fact *= i; 23 | } 24 | void show() 25 | { 26 | cout << "\nFactorial is: " << fact; 27 | } 28 | }; 29 | int main() 30 | { 31 | Factorial f1(6); 32 | f1.calculate(); 33 | f1.show(); 34 | 35 | Factorial f2(f1); 36 | f2.calculate(); 37 | f2.show(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Templates) - Assignment - 35/Problem1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | Y add(X x, Y y) 5 | { 6 | return x + y; 7 | } 8 | int main() 9 | { 10 | cout << add(5, 3.2); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Templates) - Assignment - 35/Problem10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int rem(int num) 4 | { 5 | return (num % 10); 6 | } 7 | template 8 | void hashTable(X table[], X num) 9 | { 10 | table[rem(num)] = num; 11 | } 12 | int main() 13 | { 14 | int table[10]; 15 | hashTable(table, 50); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Templates) - Assignment - 35/Problem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | Y largestNo(X x, Y y) 5 | { 6 | return x > y ? x : y; 7 | } 8 | int main() 9 | { 10 | cout< 2 | using namespace std; 3 | template 4 | Y largestNo(X x, Y y, Z z) 5 | { 6 | return x > y ? x > z ? x : z : y; 7 | } 8 | int main() 9 | { 10 | cout << largestNo(53, 443.2,9); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Templates) - Assignment - 35/Problem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | void swap(X &x, Y &y) 5 | { 6 | Y temp = x; 7 | x = y; 8 | y = x; 9 | } 10 | int main() 11 | { 12 | float x = 5.2, y = 3.33; 13 | cout << "\nBefore swapping: "; 14 | cout << x << " " << y; 15 | swap(x, y); 16 | cout << "\nAfter swapping: "; 17 | cout << x << " " << y; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Templates) - Assignment - 35/Problem5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | Y add(X x, Y y) 5 | { 6 | return x + y; 7 | } 8 | int main() 9 | { 10 | cout< 2 | using namespace std; 3 | template 4 | X sumOfArray(X arr[], int length) 5 | { 6 | X sum = 0; 7 | for (int i = 0; i < length; i++) 8 | sum += arr[i]; 9 | return sum; 10 | } 11 | int main() 12 | { 13 | float arr[] = {3, 5.4, 6, 7, 8}; 14 | int brr[] = {2, 3, 4, 5}; 15 | int size = 5; 16 | cout << sumOfArray(arr, size) << endl; 17 | cout << sumOfArray(brr, 4); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Templates) - Assignment - 35/Problem8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | class Stack 5 | { 6 | private: 7 | int top; 8 | X stack[100]; 9 | 10 | public: 11 | Stack() { top = -1; } 12 | void push(X data) { stack[++top] = data; } 13 | X pop() { return stack[top--]; } 14 | }; 15 | int main() 16 | { 17 | Stack int_stack; 18 | Stack str_stack; 19 | int_stack.push(4); 20 | str_stack.push("Ajay"); 21 | cout << int_stack.pop() << endl; 22 | cout << str_stack.pop() << endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Templates) - Assignment - 35/Problem9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | Y add(X x, Y y) 5 | { 6 | return x + y; 7 | } 8 | int main() 9 | { 10 | cout << add(5, 3.2); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | int real, img; 6 | 7 | public: 8 | Complex() {} 9 | Complex(int x) 10 | { 11 | real = x; 12 | img = x; 13 | } 14 | void display() 15 | { 16 | cout << "Img: " << img << " and Real: " << real << endl; 17 | } 18 | }; 19 | int main() 20 | { 21 | Complex c1; 22 | int x = 5; 23 | c1 = x; 24 | c1.display(); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Dollar; 4 | class Rupee 5 | { 6 | private: 7 | float rupee; 8 | 9 | public: 10 | Rupee() { rupee = 0; } 11 | Rupee(float r) { rupee = r; } 12 | float getRupee() { return rupee; } 13 | void display() { cout << "Rupee = " << rupee << endl; } 14 | }; 15 | class Dollar 16 | { 17 | private: 18 | float dollar; 19 | 20 | public: 21 | Dollar() { dollar = 0; } 22 | Dollar(Rupee r) { dollar = r.getRupee() / 82.0; } 23 | float getDollar() { return dollar; } 24 | operator Rupee() 25 | { 26 | return dollar * 82; 27 | } 28 | void display() { cout << "Dollar = " << dollar << endl; } 29 | }; 30 | int main() 31 | { 32 | Rupee r = 23; 33 | Dollar d = r; // Rupee to Dollar conversion 34 | d.display(); 35 | r.display(); 36 | r = d; // Dollar to Rupee Conversion 37 | d.display(); 38 | r.display(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Complex 4 | { 5 | int real, img; 6 | 7 | public: 8 | void setData(int x, int y) 9 | { 10 | real = x; 11 | img = y; 12 | } 13 | operator long() 14 | { 15 | return real + img; 16 | } 17 | explicit operator int() 18 | { 19 | return real + img; // you can also return img 20 | } 21 | void display() 22 | { 23 | cout << "Img: " << img << " and Real: " << real << endl; 24 | } 25 | }; 26 | int main() 27 | { 28 | Complex c1; 29 | c1.setData(5, 4); 30 | // int x; 31 | // x = c1; 32 | // cout << "Value is: " << x << endl; 33 | // c1.display(); 34 | cout << c1 << endl; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Product 4 | { 5 | int x, y; 6 | 7 | public: 8 | void setData(int a, int b) 9 | { 10 | x = a; 11 | y = b; 12 | } 13 | int getX() { return x; } 14 | int getY() { return y; } 15 | void display() { cout << "x = " << x << " y = " << y << endl; } 16 | }; 17 | class Item 18 | { 19 | int a, b; 20 | 21 | public: 22 | Item() {} 23 | Item(Product p) 24 | { 25 | a = p.getX(); 26 | b = p.getY(); 27 | } 28 | void display() { cout << "a = " << a << " b = " << b << endl; } 29 | }; 30 | int main() 31 | { 32 | Item i1; 33 | Product p1; 34 | p1.setData(3, 4); 35 | i1 = p1; 36 | p1.display(); 37 | i1.display(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Item 4 | { 5 | int a, b; 6 | 7 | public: 8 | Item() {} 9 | Item(int x, int y) 10 | { 11 | a = x; 12 | b = y; 13 | } 14 | 15 | void display() { cout << "a = " << a << " b = " << b << endl; } 16 | }; 17 | class Product 18 | { 19 | int x, y; 20 | 21 | public: 22 | void setData(int a, int b) 23 | { 24 | x = a; 25 | y = b; 26 | } 27 | int getX() { return x; } 28 | int getY() { return y; } 29 | operator Item() 30 | { 31 | Item i(4, 3); 32 | return i; 33 | } 34 | void display() { cout << "x = " << x << " y = " << y << endl; } 35 | }; 36 | 37 | int main() 38 | { 39 | Item i1; 40 | Product p1; 41 | i1 = p1; 42 | i1.display(); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Time 4 | { 5 | private: 6 | int hrs, minute, second; 7 | 8 | public: 9 | Time() {} 10 | Time(int d) 11 | { 12 | hrs = d / 3600; 13 | d = d % 3600; 14 | minute = d / 60; 15 | second = d % 60; 16 | } 17 | void display() { cout << "Hours = " << hrs << ", Minute = " << minute << ", second = " << second << endl; } 18 | }; 19 | int main() 20 | { 21 | int duration; 22 | cout << "Enter duration in seconds: "; 23 | cin >> duration; 24 | Time t1 = duration; 25 | t1.display(); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Rupee 4 | { 5 | private: 6 | int rupee; 7 | 8 | public: 9 | Rupee() { rupee = 0; } 10 | Rupee(int r) { rupee = r; } 11 | operator int() 12 | { 13 | return rupee; 14 | } 15 | }; 16 | int main() 17 | { 18 | Rupee r = 10; 19 | int x = r; 20 | cout << x; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Typecasting and Conversion) - Assignment-29/Problem9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Dollar 4 | { 5 | private: 6 | int dollar; 7 | 8 | public: 9 | Dollar() { dollar = 0; } 10 | Dollar(int r) { dollar = r; } 11 | void display() { cout << "Dollar = " << dollar << endl; } 12 | }; 13 | int main() 14 | { 15 | int x = 50; 16 | Dollar d; 17 | d = x; 18 | d.display(); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Virtual Function, Abstract Class) - Assignment - 33/Problem1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class shape 4 | { 5 | protected: 6 | double x, y; 7 | 8 | public: 9 | void setData(int x, int y) 10 | { 11 | this->x = x; 12 | this->y = y; 13 | } 14 | virtual void displayArea() = 0; 15 | }; 16 | class Triangle : public shape 17 | { 18 | public: 19 | void displayArea() 20 | { 21 | cout << "\nTriangle area is: " << x * y / 2.0; 22 | } 23 | }; 24 | class Rectangle : public shape 25 | { 26 | public: 27 | void displayArea() 28 | { 29 | cout << "\nRectangle area is: " << x * y; 30 | } 31 | }; 32 | int main() 33 | { 34 | Triangle t; 35 | Rectangle r; 36 | 37 | t.setData(13, 10); 38 | r.setData(14, 18); 39 | 40 | t.displayArea(); 41 | r.displayArea(); 42 | return 0; 43 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Virtual Function, Abstract Class) - Assignment - 33/Problem3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class A 4 | { 5 | private: 6 | int x; 7 | 8 | public: 9 | A(int x) { this->x = x; } 10 | void swap(A *num) 11 | { 12 | int temp = x; 13 | x = num->x; 14 | num->x = temp; 15 | } 16 | void showData() { cout << "X = " << x << endl; } 17 | }; 18 | int main() 19 | { 20 | A obj1(5), obj2(3); 21 | obj1.showData(); 22 | obj2.showData(); 23 | obj1.swap(&obj2); // you can use also reference 24 | obj1.showData(); 25 | obj2.showData(); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Virtual Function, Abstract Class) - Assignment - 33/Problem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class shape 4 | { 5 | protected: 6 | double l1, l2; 7 | 8 | public: 9 | void setData(int x, int y) 10 | { 11 | l1 = x; 12 | l2 = y; 13 | } 14 | virtual void displayArea() = 0; 15 | }; 16 | class Triangle : public shape 17 | { 18 | public: 19 | void displayArea() { cout << "\nArea of triangle is: " << 0.5 * l1 * l2; } 20 | }; 21 | class Rectangle : public shape 22 | { 23 | public: 24 | void displayArea() { cout << "\nArea of Rectangle is: " << l1 * l2; } 25 | }; 26 | int main() 27 | { 28 | Triangle t; 29 | Rectangle r; 30 | t.setData(1, 2); 31 | r.setData(1, 2); 32 | t.displayArea(); 33 | r.displayArea(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Virtual Function, Abstract Class) - Assignment - 33/Problem5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | class Photon 6 | { 7 | protected: 8 | double waveLength; 9 | Photon(double waveLength) { this->waveLength = waveLength / pow(10, -10); } 10 | }; 11 | class calculatePhotonEnergy : public Photon 12 | { 13 | private: 14 | double energy; 15 | 16 | public: 17 | calculatePhotonEnergy(int p) : Photon(p) {} 18 | void calEnergy() 19 | { 20 | // Photon energy formula 21 | // E = hc/lemda 22 | // where h = 6.626*10^-34 js 23 | // c = 3 * 10^-8 ms 24 | energy = (6.626 * (pow(10, -34)) * 3 * pow(10, 8)) / waveLength; 25 | cout << "\nEnergy of photon is: " << energy; 26 | } 27 | }; 28 | int main() 29 | { 30 | calculatePhotonEnergy e(0.5); 31 | e.calEnergy(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Virtual Function, Abstract Class) - Assignment - 33/Problem7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Matrix 5 | { 6 | protected: 7 | int num1, num2, num3, num4; 8 | Matrix(int x, int y, int z, int p) 9 | { 10 | num1 = x; 11 | num2 = y; 12 | num3 = z; 13 | num4 = p; 14 | } 15 | }; 16 | class cal_determinant : public Matrix 17 | { 18 | private: 19 | int determinant; 20 | 21 | public: 22 | cal_determinant(int x, int y, int z, int p) : Matrix(x, y, z, p) {} 23 | void calDeterminant() 24 | { 25 | determinant = fabs(num1 * num4 - num2 * num3); 26 | cout << "\nDeterminant of matrix is: " << determinant; 27 | } 28 | }; 29 | int main() 30 | { 31 | cal_determinant obj(1, 2, 3, 4); 32 | obj.calDeterminant(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Virtual Function, Abstract Class) - Assignment - 33/Problem8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class Proof 4 | { 5 | protected: 6 | int x, y; 7 | 8 | public: 9 | Proof(int x, int y) 10 | { 11 | this->x = x; 12 | this->y = y; 13 | } 14 | }; 15 | class Compute : public Proof 16 | { 17 | public: 18 | Compute(int x, int y) : Proof(x, y) {} 19 | void rightAngleTriangle() 20 | { 21 | } 22 | }; 23 | int main() 24 | { 25 | Compute c(1, 2); 26 | c.rightAngleTriangle(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /C++ Language Assignments/C++(Virtual Function, Abstract Class) - Assignment - 33/Problem9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class volume 4 | { 5 | protected: 6 | double x, y; 7 | 8 | public: 9 | void setData(int x, int y = 0) 10 | { 11 | this->x = x; 12 | this->y = y; 13 | } 14 | virtual void displayVolume() = 0; 15 | }; 16 | class cube : public volume 17 | { 18 | public: 19 | void displayVolume() { cout << "\nCube volume is: " << x * x * x; } 20 | }; 21 | class sphere : public volume 22 | { 23 | public: 24 | void displayVolume() { cout << "\nSphere volume is: " << (4 * 3.14 * x * x) / 3; } 25 | }; 26 | int main() 27 | { 28 | cube c; 29 | c.setData(2); 30 | sphere s; 31 | s.setData(5); 32 | c.displayVolume(); 33 | s.displayVolume(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Competitive Programming/Problem-1-Pallindrome_Integer.cpp: -------------------------------------------------------------------------------- 1 | /* LeetCode Problem Number:- 09 */ 2 | class Solution { 3 | public: 4 | bool isPalindrome(int x) { 5 | if (x < 0) 6 | return false; 7 | long int reverseNum = 0; 8 | for (long int i = x; i != 0; i /= 10) 9 | reverseNum = reverseNum * 10 + i % 10; 10 | if (x == reverseNum) 11 | return true; 12 | return false; 13 | } 14 | }; -------------------------------------------------------------------------------- /Projects/C Languages Projects/C Library On Analytic Geometry/Problem3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* This function calculate area shaped having three vertices */ 6 | double find_area(double x1, double y1, double x2, double y2, double x3, double y3) 7 | { 8 | /* Area of Triangle(three vertice shaped) */ 9 | 10 | /* Formula 11 | 0.5 * (x1(y2-y3) + x2(y3-y1)+ x3(y1-y2)) */ 12 | 13 | /* This function handle all the situatio like all coordinate are pesent in same lines etc */ 14 | 15 | double area = 0.5 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)); 16 | return fabs(area); // area unit always postive 17 | } 18 | 19 | int main() 20 | { 21 | printf("Area: %.2lf", find_area(0, 0, 3, 4, 3, 3)); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Projects/C++ Languages Projects/Student Record using File Handling/main.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajaysoni12/MySirg-Saurabh-Shukla-Sir-C-langauge-CPP-Language-DSA-IOT-Course-Assignments-with-Solution/5ddc35985dde065f74b7c4b10790f23178465b62/Projects/C++ Languages Projects/Student Record using File Handling/main.exe -------------------------------------------------------------------------------- /Projects/C++ Languages Projects/Student Record using File Handling/studentData.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajaysoni12/MySirg-Saurabh-Shukla-Sir-C-langauge-CPP-Language-DSA-IOT-Course-Assignments-with-Solution/5ddc35985dde065f74b7c4b10790f23178465b62/Projects/C++ Languages Projects/Student Record using File Handling/studentData.exe -------------------------------------------------------------------------------- /Projects/C++ Languages Projects/Student Record using File Handling/studentData.txt: -------------------------------------------------------------------------------- 1 | 2 | 1878006816 3 | Ajay soni 4 | 20 5 | btech 6 | 1878006816 7 | dgdg 8 | 34 9 | dga 10 | 1993176701 11 | aJAY DGFA 12 | 35 13 | 234 -------------------------------------------------------------------------------- /Projects/C++ Languages Projects/Student Record using File Handling/studentId.txt: -------------------------------------------------------------------------------- 1 | 2 | 1993176701 -------------------------------------------------------------------------------- /Projects/C++ Languages Projects/Tic-Tac-Toe Game/TIC-TAC-TOE GAME VIDEO.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ajaysoni12/MySirg-Saurabh-Shukla-Sir-C-langauge-CPP-Language-DSA-IOT-Course-Assignments-with-Solution/5ddc35985dde065f74b7c4b10790f23178465b62/Projects/C++ Languages Projects/Tic-Tac-Toe Game/TIC-TAC-TOE GAME VIDEO.mp4 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![SaurabhSuklaSirg](https://user-images.githubusercontent.com/106678641/185948925-36f18cf7-a1dd-4bc7-bd72-9ba0761b3094.jpg) 2 | 3 |

Saurabh Sukla Sir(MySirg)

4 | 5 | Here, I upload all Asignments and there solutions of Bootcamp course (C, C++ Languages , Data Structure and alogorithm with Internet Of Thing and Many More).
6 | 7 | Saurabh Sukla sir cover more than 800+ Assignment question with 13+ projects based on c, c++, dsa and iot. 8 | 9 | 10 | --------------------------------------------------------------------------------