Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
1667301350553.png

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 :

1667306898384.png


You did not specify the specific array element to print.

Is your compiler not showing you error dialog ?


Regards, Dana.
 
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.
 
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top