0
print 1 to end square of numbers in c
using function in c write a program to 1 to end(entered by user) square of numbers. #include<stdio.h> int square(int x); int main() { int n,i,s; printf("Enter the value of n"); scanf("%d",&n); printf("%d",square(i)); } int square(int i){ int n,s; for(i=1;i<=n;i++){ s=i*i; printf("%d %d",i,s); } }
1 Answer
+ 1
I've added comments to point out issues.
#include<stdio.h>
int square(int x);
int main()
{
int n,i,s; // s is never used
printf("Enter the value of n");
scanf("%d",&n);
printf("%d",square(i)); // i hasn't been assigned
}
int square(int i){
int n,s;
for(i=1;i<=n;i++){ // n hasn't been assigned
s=i*i;
printf("%d %d",i,s);
}
} // Failed to return a value so garbage will be printed