the program is not runing in C

Status
Not open for further replies.

sxy

Member
Code:
#include <stdio.h>
int multiplication(int a,int b)
{
int c;
c=a*b;
return c;
}
void main(void)
{
int r;
r = multiplication(2,8);
printf(“%d”,r);
}

I should get 16 but it is not runing.
why?
thanks a lot
 
I get a compile error, on the quotation marks surrounding the %d\n,
says they are non ascii characters, so I replaced by double quote marks,
and it compiled and ran.

Code:
printf("%d",r);


Regards, Dana.
 
Just tried it - doesn't work - but simple error:

Fixed:

C:
#include <stdio.h>

int multiplication(int a,int b)
{
    int c;
    c=a*b;
    return c;
}

void main(void)
{
    int r;
    r = multiplication(2,8);
    printf("%d",r);
}

Wrong punctuation marks around %D in printf.

You can try it on-line at:

 
#include <stdio.h>
int multiplication(int a,int b)
{
int c;
c=a*b;
return c;
}
void main(void)
{
int r;
r = multiplication(2,8);
printf(“%d”,r);
}
 
some text editors actually invert the comma, but in C they are the same character

The extended ones will not work..
 
#include <stdio.h>
int main() {
//array declaration
int rollNo[10];

//taking inputs
for(int i=0;i<10;i++)
scanf("%d",&rollNo);

//printing
for(int i=0;i<10;i++)
printf("%d ",rollNo);
return 0;
}
the program, is not runing.
It should take 10 integers from the user and then print them again.
 
Last edited:
Here is your error :



You did not specify the specific array element to print.

Is your compiler not showing you error dialog ?


Regards, Dana.
 
scanf() wants a keyboard input....
char input[3];
for(int i=0;i<10;i++)
{
scanf("%c",input) ;
rollNo[1] = atoi(input);
}

Scanf() does not work on that web site??
 
Try this one

Scanf works here..
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
//array declaration
int rollNo[10];
char inpt[3];

//taking inputs
for(int i=0;i<10;i++)
    {
    scanf("%s",inpt);
    rollNo = atoi(inpt);
    }
//printing
for(int i=0;i<10;i++)
printf("%d ",rollNo);
return 0;
}
 
Should this :

Code:
for(int i=0;i<10;i++)
    {
    scanf("%s",inpt);
    rollNo = atoi(inpt);
    }

be this :

Code:
for(int i=0;i<10;i++)
    {
    scanf("%s",inpt);
    rollNo[i] = atoi(inpt);
    }

Also do same for rollNo in print statement, eg use as array element....


Regards, Dana.
 
Last edited:
It should be like this
#include <stdio.h>
int multiplication(int a,int b)
{
int c;
c=a*b;
return c;
}
void main(void)
{
int r;
r = multiplication(2,8);
printf("%d",r);
}

Please note that your “%d” looks different than mine. The online C compiler found this error when I copy pasted your code.
 
Perhaps you should try reading the thread?, that answer has long since been given - more than once!.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…