logo codesdope
Level 1
1.
What would be the output of the following programs:

a.

#include <stdio.h>
int main()
{
    int x = 3.9;
    printf("%d\n",x);

    return 0;
}

Answer
3

b.

#include <stdio.h>
int main()
{
    char x = 'A';
    printf("%d\n",x);
    return 0;
}

Answer
65

c.

#include <stdio.h>
int main()
{
    char x = 'A';
    printf("%d\n",x+15);
    return 0;
}

Answer
80

d.

#include <stdio.h>
int main()
{
    printf("%c\n",80);
    return 0;
}

Answer
P
Level 2
1.
Write a C program to take an int, a float and a char input from user and print them on the screen.
Answer
#include <stdio.h>
main(){
	int i;
	float fl;
	char ch;
	scanf("%d", &i);         //taking integer input
	scanf("%f", &fl);        //taking float input
	scanf(" %c", &ch);        //taking character input
	printf("integer : %d\n", i);
	printf("float : %f\n", fl);
	printf("character : %c\n", ch);
}
									

2.
Take the values of length and breath of a rectangle from the user and print the area of it on the screen.
Answer
#include <stdio.h>
main(){
	float l, b, area;
	printf("\nEnter length of rectangle");
	scanf("%f", &l);
	printf("\nEnter breadth of rectangle");
	scanf("%f", &b);
	area = l * b;
	printf("\nArea of rectangle = %f", area);
}
									

3.
Take a char input from user and print it's ASCII value.
Answer
#include <stdio.h>
main(){
	char ch;
	printf("Enter a character");
	scanf("%c", &ch);
	printf("\nASCII value of the character entered is %d", ch);
}
									

4.
Take a float input from the user and type cast it to int and print it on the screen.
Answer
#include <stdio.h>
main(){
	float fl;
	scanf("%f", &fl);   //taking float input from the user
	int i = (int)fl;    //typecasting float input to integer and assigning it to an integer variable i
	printf("%d", i);
}
									

5.
Write a C program to take two integer inputs from the user and print the sum and the product of them.

6.
Take value of length and breath of a rectangle from the user as float. Find its area and print it on the screen after type casting it to int.
Answer
#include <stdio.h>
main(){
	float l, b, area;
	printf("\nEnter length of rectangle");
	scanf("%f", &l);
	printf("\nEnter breadth of rectangle");
	scanf("%f", &b);
	area = l * b;
	printf("\nArea of rectangle = %d", (int)area);
}
									

7.
Write a program to print square of a number. e.g.-
INPUT : 2         OUTPUT : 4
INPUT : 5         OUTPUT : 25
Answer
#include <stdio.h>
main(){
	int i;
	printf("Enter the number");
	scanf("%d", &i);
	printf("\nSquare of the number is %d", (i*i));
}
									

Doubt? Ask question
Close

Welcome.please sign up.

Close

Welcome.please login.