Question 2

Question: Write a program that convert alphabet characters to be upper-cased
Answer:
Before we go to code this program, we wonder that how can the computer knows what characters are uppercase or lowercase
Thanks to ASCII, we have

The design of this program will be almost similar to the question 1; other words, we just need to add a small 'function' into the infinite loop

#include <stdio.h>

int main(void){
int c;
for( ; ; ){
c = getchar();
if(c == EOF)
break;
if( (c >= 97) && (c <= 122) ) /*if it is lowercase*/
c -= 32;                 /*meaning new c = old c - 32 (gap)*/
putchar(c);
}
return 0;
}

Output:




No Response to "Question 2"

Post a Comment

 

Copyright © 2013-2014 Lai Duy Thanh All rights reserved.