0% found this document useful (0 votes)
38 views

PPS T2 Solution

COEP Technological University (COEP Tech) is a unitary public university of the Government of Maharashtra formerly known as College of Engineering Pune. The document contains 4 questions asking about C programming concepts like while and do-while loops, reversing a 5 digit number, and determining if a character entered is a capital letter, small letter, digit or special symbol based on its ASCII value range.

Uploaded by

Harshit Misra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

PPS T2 Solution

COEP Technological University (COEP Tech) is a unitary public university of the Government of Maharashtra formerly known as College of Engineering Pune. The document contains 4 questions asking about C programming concepts like while and do-while loops, reversing a 5 digit number, and determining if a character entered is a capital letter, small letter, digit or special symbol based on its ASCII value range.

Uploaded by

Harshit Misra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COEP Technological University (COEP Tech)

A Unitary Public University of Government of Maharashtra


(Formerly College of Engineering Pune)

Phone: +91-20-25507000 Website: www.coep.org.in


Fax : +91-20-25507299 E-mail:
[email protected]

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

iii #include<stdio.h> iv void main()


void main() { int i,j,k,x=0;
{ for(i=0;i<5;i++) 0,1,2,3,4
int i,j,x=0; for(j=0;j<i;j++) 0; 0,1 ; 0,1,2 ; 0,1,2,3 ;0,1,2,3,4
for(i=0;i<5;i++) 0,1,2,3,4 {
for(j=0;j<i;j++) 0; 0,1 ; 0,1,2 ; 0,1,2,3 ;0,1,2,3,4 k=(i+j-1);
{ if(k%2==0)
x+=(i+j-1); x+=k;
printf("%d ",x); else
} if(k%3==0)
printf("\nx=%d",x); x+=k-2;
} printf("%d ",x);
}
Output: printf("\nx=%d",x);
0 1 3 5 8 12 15 19 24 30 }
x=30 Output:
0 0 2 4 5 9 10 14 14 20
x=20
Q.2 a) Differentiate while and do while with example 04
Ans:

Students can write at least four points with example

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;

reverse=d5*10000 + d4*1000 + d3*100 + d2*10 + d1*1;


printf("Reverse number of %d is %d\n",num,reverse);

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.

Characters ASCII Values

A-Z 65 – 90

a-z 97 – 122

0-9 48 – 57

Special Symbols 0 - 47, 58 - 64, 91 - 96, 123 - 127

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");
}

You might also like