This commit is contained in:
RafayAhmad7548 2024-06-16 18:53:25 +05:00
parent 37776af5db
commit ab03d5f10c
4045 changed files with 286212 additions and 3 deletions

View file

@ -0,0 +1,31 @@
#include <iostream>
using namespace std;
// Global Variables/functions not allowed
// Recursive function to calculate the length of a string
int getStringLength(char* s){ // Default arguments not allowed
if(s[0] == '\0') return 0;
else return 1 + getStringLength(s+1);
}
int main() {
// Test cases, don't modify
string test1 = "123456";
string test2 = "moyeMoye";
string test3 = ""; // Empty string
string test4 = "OOP Lab";
string test5 = "Recursion is fun!";
// You can make modifications down here....//
cout << " String = " << test1 << ", Expected = 6, Your output = " << getStringLength(&test1[0]) << endl;
cout << " String = " << test2 << ", Expected = 8, Your output = " << getStringLength(&test2[0]) << endl;
cout << " String = " << test3 << ", Expected = 0, Your output = " << getStringLength(&test3[0]) << endl;
cout << " String = " << test4 << ", Expected = 7, Your output = " << getStringLength(&test4[0]) << endl;
cout << " String = " << test5 << ", Expected = 17, Your output = " << getStringLength(&test5[0]) << endl;
return 0;
}

View file

@ -0,0 +1 @@
{"version":1,"resource":"file:///home/rafayahmad/Downloads/232526/q1.cpp","entries":[{"id":"1QKo.cpp","timestamp":1717740431705}]}