It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I know the program below is almost wrong and I am seeking for a hep to fix that UP
please help:
#include <stdio.h>
#include <string.h>
int i;
float r;
char c;
char s[48];
int main() {
i=4;
r=3;
c='z';
strcpy(s,"Hi There");
printf("i=%d,r=%d,c=%d")
}
First of all, when you say something is wrong, it might help to point out what it is that is wrong. E.g. add the expected and the actual output, or errors you get when compiling or linking.
Secondly, the error is probably that the printf call prints weird values. It's because you tell it to print three values but you don't actually provide the values to print. Change to
printf("i=%d,r=%d,c=%d", i, r, c);
#include <stdio.h>
#include <string.h>
int main(){
int i;
float r;
char c;
char s[48];
i=4;
r=3.0;
c='z';
strcpy(s,"Hi There");
printf("i=%d, r=%hf, c=\'%c\', s=\"%s\"", i, r, c, s);
return 0;
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an array of chars "0x55".
What I want to do is convert it to a char which is going to be U (because ASCII 0x55 = U).
So how to do this conversion?
#include <windows.h>
int main()
{
array[] = "0x55"
char test;
**// I want to move the string to that test to be one character which is U**
}
Any suggestions?
I think this is what you are after:
int main(int argc,char**argv)
{
char array[] = "0x55";
int value;
char test;
sscanf(array,"%x",&value);
test = value;
return 0;
}
In C++, I would code it a little differently, but this seems more like a C question.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
#include<stdio.h>
void main()
{
float i,j;
i=??;
j=i+1;
if(i==j)
printf("Bug");
}
My teacher gave me this qns to find the value of i so that the printf executes.
He said this is a common bug in a lot of languages.
Always try the boundaries for odd behavior. This worked for me:
#include <float.h>
int _tmain(int argc, _TCHAR* argv[])
{
float i,j;
i = FLT_MAX;
j = i + 1;
if(i == j)
{
printf("they're the same");
}
return 0;
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Basically i want to create a recursive function to implement this program in C
#include <stdio.h>
main()
{
float guess=1,num,num1;
int i;
printf("enter any number:\n");
scanf("%f",&num);
num1=num;
for (i=1;num1>1;i++,num1/=10); //to calculate no of digits in input
i=i/2;
printf("i:%d\n",i); //to make a better guess
for (;i>0;i--,guess*=10);
printf("guess = %f\n",guess);
for (i=1;i<=10;i++) //evaluate square root improving accuracy with each loop
{
guess=(guess+num/guess)/2;
}
printf("sqrt: %f\n",guess);
}
Something like this:
#include <math.h>
#include <float.h>
float MySqrt(float num, float prev)
{
float next = (prev+num/prev)/2;
if (fabs(next-prev)<FLT_EPSILON*next)
return next;
return MySqrt(num, next);
}
To call it, pass 1.0 as your initial guess for the prev parameter.
You can easily make this fail with a stack overflow by passing in bad data, but you probably aren't going to be tested on that in this assignment.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Note: The question has been edited to make the problem go away.
I have written this code to reverse an array using functions. But there is an error in line 24 saying ' ) expected'. I have read it again and again but i couldn't find the error. Can anybody please reveal it and tell me how to remove it?
#include<stdio.h>
#include<conio.h>
#define max 5
/*function prototype*/
void reverse(int[],int);
void main()
{
int arr[max]={1,2,3,4,5};
int i,j;
clrscr();
printf("the list before reversing:\n");
for(i=0;i<max;i++)
printf("%d",arr[i]);
reverse(arr,max);
printf("\n the list after reversing:\n");
for(i=0;i<max;i++)
printf("%d",arr[i]);
getch();
}
/*function for reversing elements of array*/
void reverse(int num[],int max)
{
int i,j,temp;
for(i=0,j=max-1;i<max/2;i++,j--)
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
max is defined as a macro. So after preprocessing it becomes
void reverse(int num[],int 5)
Which is not valid and you are getting ' ) expected'. If max is constant then there is no need to pass it as a parameter. And also you have a missing for in the function.
You seem to be missing the for keyword in the loop header in reverse().
EDIT:
Ok, ok my first answer was stupid...
(Answered without thinking enough)
Now I got it:
The problem is
#define max 5
Later max (=5) is used as a parameter!
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
#include <stdio.h>
#include <string.h>
int test(char ch [10],int i,int j )
{
if(i>=j) return 1;
else if (ch[i]!=ch[j]) return 0;
else return (test(ch,i++,j--));
}
int main ()
{
char ch[10];
int m,k;
printf("Donner une chaine de caracteres :\n");
scanf("%s",ch);
k=strlen(ch);
m=test(ch,0,k-1);
if (m==1) printf ("expression palindrome \n");
else printf ("expression non palindrome \n");
return 0;
}
Try replacing this:
else return (test(ch,i++,j--));
...with this:
else return (test(ch,i+1,j-1));
There's no need to assign back into 'i' and 'j' when making that call, since you don't reference them again in the same function invocation. Moreover, i++ evaluates to the original value of i, and not the value of i + 1 (which is what you want here).
So your original code would never actually modify i and j, which would cause it to recurse infitely and cause a stack overflow (so I can't believe people were saying that this wasn't appropriate for SO).