Skip to main content

Posts

Showing posts from September, 2023

HOW TO PASS ARRAY IN FUNCTION

       SUM OF ALL ELEMENTS OF ARRAY   #include <iostream> using namespace std;   int abc(int brr[], int n)    //abc is the name of function {               int sum=0;               for(int i=0; i<n; i++)               {                              sum+=brr[i];               }               return sum; }   int main() { int n = 10; int arr[n]= {1,2,3,4,5,6,7,8,9,10};   cout<<"Sum is : "<<abc(arr,n)<<endl;        ...

C++ code for find the Length of the string without using strlen() function.

#include <iostream> #include <string> using namespace std; int main() {     string str;     int length = 0;     cout << "Enter a string: " << endl;     getline(cin, str);     // this will take only one word               cin>>str;     for (int i = 0; str[i] != '\0'; i++) {         length++;     }     // or we can write                              length = str.length();     cout << "Length of string: " << length << endl;     return 0; }