logo codesdope
Level 1
1.
Point out the errors in the following codes:

a.

#include <stdio.h>
int main(){
    printf(Hello);
    return 0;
}

Answer
#include <stdio.h>
int main(){
    printf("Hello");
    return 0;
}
									
printf("Hello") insteaad of printf(Hello)

b.

#include <stdio.h>
/*Using comment
/*This is a comment*/
*/
int main(){
    printf("Hello\n");
    return 0;
}

Answer
Comment inside comment is invalid

c.

#include <stdio.h>
int main(){
    printf("Hello")
    return 0
}

Answer
#include <stdio.h>
int main(){
    printf("Hello");
    return 0;
}
									
Missing ;

d.

int main(){
    printf(Hello);
    return 0
}

Answer
#include <stdio.h>
int main(){
    printf("Hello");
    return 0;
}
									
stdio.h not included
Level 2
1.
Write a C program to print
*
**
***
****
on screen.
Answer
#include <stdio.h>
main() {
	printf("*\n");
	printf("**\n");
	printf("***\n");
	printf("****\n");
}
									

2.
Store two integers in two variables x and y. Print the sum of the two.
Answer
#include <stdio.h>
main() {
	int x, y, sum;  //declaration of integer variables
	x = 3;
	y = 5;
	sum = x + y;
	printf("%d\n", sum);
}
									

3.
Store two integers in two variables x and y. Print the product of the two.
Answer
#include <stdio.h>
main() {
	int x, y, product;  //declaration of integer variables
	x = 3;
	y = 5;
	product = x * y;
	printf("%d\n", product);
}
									

4.
Print the following pattern on the screen
****
 ** 
  *  
 ** 
****

5.
Write a C program to take two integer inputs from user and print the sum and the product of them.
Answer
#include <stdio.h>
main() {
	int x, y, sum, product;
	scanf("%d", &x);                 //taking input for value of x
	scanf("%d", &y);                 //taking input for value of y
	sum = x + y;
	product = x * y;
	printf("sum = %d\n", sum);
	printf("product = %d\n", product);
}
									

6.
Take two integer inputs from the user. First calculate the sum of two then product of two. Finally, print the sum and the product of both obtained results.
Answer
#include <stdio.h>
main() {
	int x, y, sum, product;
	scanf("%d", &x);                 //taking input for value of x
	scanf("%d", &y);                 //taking input for value of y
	sum = (x + y) + (x * y);
	product = (x + y) * (x * y);
	printf("sum = %d\n", sum);
	printf("product = %d\n", product);
}
									

Doubt? Ask question
Close

Welcome.please sign up.

Close

Welcome.please login.