Professional Documents
Culture Documents
Q.1 Find the output of the following code ( Each carry 2 Marks) 08
i #include<stdio.h> ii #include<stdio.h>
void main() void main()
{ {
int x=0,y=0; int i=10, j=20, k=30,num;
if(x>y) if(j>k)
y=y+1; { if(i>j)
else num=i;
{ }
if(x<0) else
y=y+2; { if(i>k)
else num=i;
y=y+5; else
} num=k;
printf("y=%d ", y); }
} printf("Num=%d", num);
}
Output: Output:
y=5 Num=30
b) A five-digit number is entered through the keyboard. Write a program to obtain the reversed 04
number and to determine whether the original and reversed numbers are equal or not.
Ans:
Sample Code:
#include<stdio.h>
void main()
{
int num,a,b,c,d,reverse,d1,d2,d3,d4,d5;
printf("Enter a 5 digit number\n");
scanf("%d",&num);
a=num/10;
d5=num%10;
b=a/10;
d4=a%10;
c=b/10;
d3=b%10;
d=c/10;
d2=c%10;
d1=d%10;
if (num = = reverse)
printf("Both the numbers are equal");
else
printf("Both the numbers are not equal");
}
c) Any character is entered through the keyboard, write a program to determine whether the character 04
entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows
the range of ASCII values for various characters.
A-Z 65 – 90
a-z 97 – 122
0-9 48 – 57
Sample Code:
#include <stdio.h>
void main() {
char ch;
printf("\nEnter Character : ");
scanf("%c", &ch);
if(ch>=65 && ch<=90)
printf("Capital");
else if(ch>=97 && ch<=122)
printf("Small Character");
else if(ch>48 && ch<=57)
printf("Number");
else if(ch>=0 && ch<=47 || ch>=58 && ch<=64 || ch>=91&&ch<=96||ch>=123 && ch<=127)
printf("Special Character");
else
printf("Wrong Input");
}