Thread for the C/C++ Beginners and Programmers!

Here are some more programs for u to try.

First Program
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter the three numbers :- ");
scanf("%d %*d %d",&a,&b,&c);
printf("%d %d %d",a,b,c);
}

Assume the input values as 55,67,90 then what will be the output of this program?

Second Program
#include<stdio.h>
main()
{
printf("C\bR\bI\bC\bK\bE\bT\b CRICKET");
}
What will be the output?

Third Program
#include<stdio.h>

main()
{
float a;
int b=5,c=2;
a=b/c;
printf("a=%f\n",a);
}
What will be the output?

Try to give all the answers without running the program!
 
The second one I think will beep after every letter then write the whole word.
The first one I think the output will be 55, 4489 and 90 (but I'm pretty sure I'm wrong)
And the third one is possibly 2.5

I'm only sure about the second one
 
whitehornmatt said:
The second one I think will beep after every letter then write the whole word.
The first one I think the output will be 55, 4489 and 90 (but I'm pretty sure I'm wrong)
And the third one is possibly 2.5

I'm only sure about the second one
I am afraid but all your answers are wrong but good try.
 
saurabh2185 said:
Can't we have a C++ program, rather then C. As i only know C++
If u know C++ then it will be a simple program for u to solve.That's not tough.
 
gaurav_indian said:
If u know C++ then it will be a simple program for u to solve.That's not tough.

But i don't know the meaning of syntax of printf, scanf.
As in C++ if we want to display result we use

cout << "\n\t Enter the Number \n";
cout << "\n\t Result = " << a;


and for input we use
cin >> b >> c;
 
saurabh2185 said:
But i don't know the meaning of syntax of printf, scanf.
As in C++ if we want to display result we use

cout << "\n\t Enter the Number \n";
cout << "\n\t Result = " << a;


and for input we use
cin >> b >> c;
In C printf is used for output on the screen and scanf is used for input.
 
dunno about the first program (dont know C),
second will give output CRICKET.
Third will be : 2.000000 (i think there are 6 zeros in float...)
 
Abhas said:
dunno about the first program (dont know C),
second will give output CRICKET.
Third will be : 2.000000 (i think there are 6 zeros in float...)
Abhas try the first one also.Both your second and third answers are correct.
 
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter the three numbers :- ");
scanf("%d %*d %d",&a,&b,&c);
printf("%d %d %d",a,b,c);
}

Assume the input values as 55,67,90 then what will be the output of this program?
i can't understand the usage of - "%*d"

will the anwer be 55 90 0 ? (0 if we initialise c to 0)
otherwise the value in c will be garbage value...
 
Last edited:
Abhas said:
i can't understand the usage of - "%*d"

i am guessing here -

will the anwer be 55 90 0 ? (0 if we initialise c to 0)
otherwise the value in c will be gargabe value...
Your guess is right Abhas.The answer will be 55 90 and a garbage value to variable c.

%*d is used for skipping the user input value.
So it goes like this in 'a' 55 will be stored then whatever is the next value that will be skipped in this case it was 67 and the next value is stored in variable 'b' that is 90.Since there is no value for 'c' it will take the garbage value.I hope now u understand that abhas but good guess and reps 4u. ;)
 
Last edited:
An easy program for you guys to try:

Code:
WAP in c/c++ which will accept a value between 1 and 7 from the user 
into an integer variable 'x'. If the value is greater than 7 or less than 1 
than the user should get the message "try again" -- 
as many times as the user continues to put a wrong value.
[b]You're not allowed to use goto [/b]

Its a pretty easy program and I expect several of you to crack it :)
 

Users who are viewing this thread

Top