0
Hi, in my output 4620160 is added extra. When nhr excuete. Why it is added in output. What is the error in the code.
4 Antworten
+ 3
You should just change the return type of all your self-defined functions to void and call them.
#include <iostream>
using namespace std;
void nh(int n1){
for(int i=0; i<n1;i++)
cout<<i;
}
void nhr(int n2){
for(int j=n2; j>=0; j--)
cout<<j;
}
void nv(int n3){
for(int k=0;k<n3; k++)
cout<<k<<endl;
}
void nvr(int n4){
for(int l=n4; l>=0; l--)
cout<<l<<endl;
}
void grid(int n5){
for(int m=0; m<n5; m++)
{cout<<m;
for(int o=m+1; o<n5+m; o++)
{cout<<o;}
cout<<endl;}
}
int main(){
int n;
cin>>n;
nh(n);
nhr(n);
grid(n);
nv(n);
nvr(n);
return 0;
}
+ 3
If your function has return type int, your function should return some integer value, e.g.
int add2(int value)
{
return (value + 2);
}
0
thanks. but my return type is int only. so why I can't use int type correct
0
ok. got it thanks