Programing Solution

  • View

  • Download

Embed Size (px)

Text of Programing Solution

1. Write a program to verify that each word of a given paragraph is started with uppercase or not. Solution: #include #include int main() { char para[20][100]; char ch; int i=0,j=0,status=1; while((ch=getchar())!=EOF) { if(ch!='\n') { if(((para[i][j-1])==32)||(j==0)) { if(isalnum(ch)) { if((isupper(ch))==0) status=0; } } para[i][j++]=ch; } else { para[i++][j]='\0'; j=0; } } (status==1)?printf("\nEach word begins with Uppercase."):printf("\nEach word doesn't begin with Uppercase."); return 0; }


Write a program that can run a *.exe file from the current directory.

Solution: #include #include #include int main(void) {

system("1.exe"); return 0; } 3. Write a C program to illustrate the use of enumerated data type.

Solution: #include int main() { enum sw{off,on}; enum sw bulb1,bulb2; int cx; printf("\nEnter Bulb1's status:\n1.on(1)\\n:?\b"); scanf("%d",&cx); bulb1=cx; if(bulb1==on) bulb2=off; else bulb2=on; if(bulb2==on) printf("\nBulb2 is switched on."); else printf("\nBulb2 is switched off."); return 0; } Define and use a structure as an argument of function as well as return type of a function. Solution: #include struct H_W BMI(struct H_W); struct H_W { int feet; int in; float weight; float mheight; float bmi; }; struct H_W BMI(struct H_W x) { x.mheight=((x.feet*12.0); x.mheight*= x.mheight; x.bmi = x.weight/ x.mheight; return (x); } int main() { 4.

struct H_W var; printf("Enter your weight:"); scanf("%f",&var.weight); printf("\nEnter your height(feet inches):"); scanf("%d %d",&var.feet,&; var=BMI(var); printf("\nYour BMI:%.3f",var.bmi); return 0; } 5. Write an user-defined function that accept a string(char array) from the terminal(command prompt) and return its reverse string.

Solution: #include #include char * strreve(); void swapp(char *,char *); void swapp(char *ch1,char *ch2) { char temp; temp=*ch1; *ch1=*ch2; *ch2=temp; } char * strreve() { int i=0,l; char *str; printf("\nEnter a string to be reversed:"); scanf("%s",str); l=strlen(str); while(i?\b"); scanf("%d",&fr); printf("\nEnter how many column in first Matrix:\n\n=>?\b"); scanf("%d",&fc); printf("\nEnter how many row in second Matrix:\n\n=>?\b"); scanf("%d",&sr); printf("\nEnter how many column in second Matrix:\n\n=>?\b"); scanf("%d",&sc); printf("\nprothom Matrixer datagulo dao(row by row):"); for(i=0;i