Message from C, C++ discussions
December 2019
β π
#include <stdio.h>
//Compiler version gcc 6.3.0
int main()
{
int i, sum=0,A,B;
printf ("input A : ");
scanf ("%d",&A);
printf ("input B : ");
scanf ("%d",&B);
printf("Numbers between A and B, divisible by 3 : \n");
for(i=A;i<B;i++)
{
if(i%3==0)
{
printf("%d",i);
printf(" ");
}
}
}
β WanzOr Have a look at this and try understanding it
β Thank you
β Very much
β One modificationβ-> for(i=A;i<=B;i++)
Not i<B
β Purge complete.
β OMG
β Welcome!
β π
β Char firstCapitalChar(char* str, int length, char putHereA){
if(str[length] == putHereA)return(str[length]);
else if(length == 0)return (char)0;
else if(putHereA == 'Z')return firstCapitalChar(str, length - 1, 'A');
else{
return firstCapitalChar(str, length, putHereA+1);
}
} this recursive function need to return me the first capital letter but it returning the last capital letter why?
β Maybe you need to pass the starting index and the last index of the string into your recursive function.... I made one and its working fine... Have a look
#include<bits/stdc++.h>
using namespace std;
char first_capital(string str,int start,int len)
{
if(start==len)
return str[len];
else if(str[start]>='A'&&str[start]<='Z')
return str[start];
else
return first_capital(str,start+1,len);
}
int main()
{
string str;
cin>>str;
cout<<"The first capital letter in the string is : "<<first_capital(str,0,str.length());
return 0;
}