C&C++ programming tricky questions
1. C++
program to calculate the sum of the digits of a number until the number is
a
single digit
Example:
Input: Enter a
number: 147
Output: 3
Explanation: 147 →
1+4+7 = 12 → 1+2 = 3
2. C program to print message (Hello
World/Hello C) without using any semicolon in program
3. C program to print your name 10 times without using
any loop or goto statement
Solutions:
1.#include <iostream.h>
Void main()
{
int number = 147;
int result;
if(number)
result = number % 9 == 0 ? 9 :
number % 9 ;
else
result
= 0;
cout<< result;
return 0;
}
2.
#include <stdio.h>
Void main()
{
if(printf("Hello world
"))
{
}
}
3. #include<stdio.h>
void main() {
static int i = 1;
if (i <= 10) {
printf("%d", i++);
main();
}
}

Wonderful Post. This is a very helpful post.If any one who want to learn C&C++ get a free demo call on 9311002620 or visit our further- https://htsindia.com/Courses/embedded-systems-and-robotics/cplusplustraininginstituteinsouthdelhi
ReplyDelete