What's code problem?

 0 ``````#include int main () { int a,b,c; c=a+b; scanf("%d",&a,&b); printf("%d",c); return 0; } `````` asked 12 Nov '15, 19:55 raseljpi11 117●1●5

 2 ১. তুমি ইউজার থেকে ইনপুট নেয়ার আগেই যোগফল লিখে ফেলছো। a, b এর মান নাও নাই, কিন্তু আগেই c= a+b যোগ করে রাখছো। ২. তুমি ইনপুট নিতে চাচ্ছো দুইটা নাম্বার কিন্তু format spacifier (%d,%f,%lf এগুলো ফরম্যাট স্পেসিফায়ার) দিয়েছো একটা। এর জন্য প্রবলেম হচ্ছে। এগুলা একদমই বেসিক লেভেলের জিনিস। শুরুর দিকের। একটু বুঝে লজিক দিয়ে চিন্তা করে করার চেষ্টা করবা। কোডটা হবে এমনঃ ``````scanf("%d %d",&a,&b); c = a+b; printf("%d",c); `````` answered 12 Nov '15, 20:48 Tamanna Nishat Rini ♦♦ 3.0k●3●12
 0 When you run this your compiler it shows a warning: too many arguments for format [-Wformat-extra-args]| Why this happened? Here in your code you declare three integer =a,b,c.In scanf function you only use one %d but you passes two arguments=&a,&b.You don't declare another %d .That's why when you input 2 numbers like =1 and 2 .one has stored address of a ( &a) but 2 doesn't find his arguments .That's why it's overflow many numbers. Another wrong is you declare c=a+b -> scanf("%d",&a,&b). This is wrong .Why? Because at first you take input then compiler shows output . Here is your full code : int main() { int a,b,c;//declare three integer variable scanf("%d %d",&a,&b);//give the two numbers in console c=a+b;//sum of two numbers. printf("%d",c);//c shows the two numbers sum. return 0; } answered 12 Nov '15, 20:15 Iftekhar Joy 11●1
 toggle preview community wiki:

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Question tags:

×402
×38

question asked: 12 Nov '15, 19:55

question was seen: 947 times

last updated: 12 Nov '15, 20:48