Sunday, July 12, 2009

Solve this simple C Program for me please...?

this program take inputs of 5 char name and count it then print it captial letters and reverse its order as well... i know this program is bad design but i m beginner...make this program like..


--Take char until we press ENTER


--Make is Capital


--Print in Reverse Order


--Count Number of Char Entered.





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


char name[5];


int i,count=0,j,nam[5];


clrscr();


printf("Enter your name:");


i=0;


while(i%26lt;5)


{


scanf("%c",%26amp;name[i]);


if(scanf)


count=count+1;


else


break;


i++;


}


printf("The length u entered is %d ",count);


nam[0]=name[0];


nam[1]=name[1];


nam[2]=name[2];


nam[3]=name[3];


nam[4]=name[4];


printf("\n\nThe name in Cappatal letters is : ");


for(j=0;j%26lt;5;j++)


printf("%c",name[j]-32);


printf("\n\nThe reverse order is : ");


for(i=4;i%26gt;=0;i--)


printf("%c",name[i]);


getch();


}

Solve this simple C Program for me please...?
#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;windows.h%26gt;


void main()


{


char name[5];


int i,count=0,j,nam[5];


system("cls");


printf("Enter your name:");


while(count%26lt;5)


{


scanf("%c",%26amp;name[count]);


if(name[count] == '\n')


break;


count=count+1;


}


printf("The length you entered is %d ",count);


nam[0]=name[0];


nam[1]=name[1];


nam[2]=name[2];


nam[3]=name[3];


nam[4]=name[4];


printf("\n\nThe name in Capital letters is : ");


for(j=0;j%26lt;count;j++)


printf("%c",name[j]-32);


printf("\n\nThe reverse order is : ");


for(i=count-1;i%26gt;=0;i--)


printf("%c",name[i]);


getch();


}





Enjoy and you were very close! :)
Reply:#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;windows.h%26gt;


#define MAXLEN 5


void main()


{


char name[MAXLEN];


int i,count=0,j;


system("cls");


printf("Enter your name:");


while(count%26lt;MAXLEN)


{


scanf("%c",%26amp;name[count]);


if(name[count] == '\n')


break;


count++;


}


printf("\n\nThe name in Capital letters is : ");


for(j=0;j%26lt;count;j++)


printf("%c",toupper(name[j]));


printf("\n\nThe reverse order is : ");


for(i=count-1;i%26gt;=0;i--)


printf("%c",name[i]);


printf("\nThe length you entered is %d ",count);


}








I tested it, works.


No comments:

Post a Comment