Upload
syed-tanveer
View
148
Download
0
Embed Size (px)
Citation preview
#include<stdio.h> #include<conio.h> #include<string.h> void Question1 (void)
{ clrscr(); printf("\tConversion of Upper Case to Lower case\ \nOr\n\tLower Case to Upper Case\n"); int a; char ch[80]; printf("Enter a string :"); fflush(stdin); gets(ch); printf("\n"); int b=strlen(ch); for(a=0;a<b;a++) { if (ch[a]>64&&ch[a]<91) ch[a]=ch[a]+32; else if (ch[a]>95&&ch[a]<122) ch[a]=ch[a]-32; } puts(ch); printf("\nTotal words =%d\n",b); }
void Question2 (void) { clrscr(); int a,b; char str[50]; printf("\t\tReverse the input string\n"); printf("Enter a string:"); fflush(stdin); gets(str); printf("\n"); a=strlen(str); for (b=a;b>=0;b--) printf("%c",str[b]); }
void Question3 (void) { clrscr(); int a,b,count=0; char ch[80]; printf("\t\tCount the number of vowels\n"); printf("Enter a string: "); fflush(stdin); gets(ch); printf("\n"); b=strlen(ch); for(a=0;a<b;a++) { if (ch[a]=='e' || ch[a]=='a'|| ch[a]=='o'|| ch[a]=='u' || ch[a]=='i') count++; else if (ch[a]=='E' || ch[a]=='A'|| ch[a]=='O'|| ch[a]=='U' || ch[a]=='I') count++; } printf("Total Words = %d \n Vowels = %d",b,count); }
void Question5 (void) { clrscr(); int a,b; char ch[80]; printf("\t\tASCII Equivalent Of CHaracter\n"); printf("Enter a string: "); fflush(stdin); gets(ch); printf("\nCharcter ASCII Equivalent\n "); b=strlen(ch); for(a=0;a<b;a++)
{ printf("%c \t %d",ch[a],ch[a]); printf("\n"); }
}
void Question4 (void)
{ clrscr(); char wwe,ch,Z[100]; int A[10],i,j,n,temp, x,y,slen,pemt;
printf("\t\tSorting\n"); printf("For number's sorting press s \nFor alphabetic sorting press p\nYour Choice\t");
fflush(stdin); scanf("%c",&wwe); switch (wwe) {
case 's': printf("Enter the no of element:");
scanf("%d",&n); printf("Enter element \in array\n");
for(i=0;i<n;i++) {
printf("Element %d is ",i+1); scanf("%d",&A[i]); }
printf("\n Element enter by you is : \n"); for(i=0;i<n;i++)
printf("%d\n",A[i]); printf("If you want to sort in ascending order\tpress a \n Or \n If you want to sort in descending\order\t press b \n"); ch=getch();
if (ch=='a') { for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if (A[i]>A[j]) { temp=A[i]; A[i]=A[j]; A[j]=temp; } } printf("\t%d\t",A[i]); } } else if (ch=='b') for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if (A[i]<A[j]) { temp=A[i]; A[i]=A[j]; A[j]=temp; } printf("\t%d\t",A[i]); } }
break;
case 'p': printf("Enter a string:");
fflush(stdin); gets(Z); slen=strlen(Z);
printf("Enter element in array\n"); for(x=0;x<slen;x++)
printf("Alphabet %d = %c\n",x+1,Z[x]); printf("\n Element enter by you is : \n");
for(x=0;x<slen;x++) printf("%c\n",Z[x]); printf("If you want to sort in ascending order\tpress a\ \n Or \n If you want to sort in descending\order\tpress b\n"); ch=getch();
if (ch=='a') {
for(x=0;x<slen;x++) {
for(y=x+1;y<slen;y++) {
if (Z[x]>Z[y]) {
pemt=Z[x]; Z[x]=Z[y]; Z[y]=pemt;
} }
printf("\t%c\t",Z[x]); }
} else if (ch=='b')
{ for(x=0;x<slen;x++) { for(y=x+1;y<slen;y++)
{ if (Z[x]<Z[y]) {
pemt=Z[x]; Z[x]=Z[y]; Z[y]=pemt; }
} printf("\t%c\t",Z[x]);
} } break;
} }
void Question6 (void) { int a[2][2]= {1,2,1,2}; int b[2][2]= {2,1,2,1}; int i,j,k,c[2][2],sum=0; clrscr(); printf("\t\tMultiplication of Two Matrices\n"); /*FOR MATRICS A */ printf("Matrics A"); for(i=0;i<2;i++) { printf("\n"); for(j=0;j<2;j++) printf("%d\t",a[i][j]); } printf("\n"); /*FOR MATRICS B */ printf("Matrics B"); for(i=0;i<2;i++) { printf("\n"); for( j=0;j<2;j++) printf("%d\t",b[i][j]); } /*FOR MATRICS C */ printf("\nMatrics C=A*B\n"); for(i=0;i<2;i++) for(j=0;j<2;j++) { sum=0; for (k=0;k<2;k++) sum=sum+a[i][k]*b[k][j]; c[i][j]=sum; } for(i=0;i<2;i++) { for( j=0;j<2;j++) printf("%d\t",c[i][j]); printf("\n"); } }
int Question7(void)
{ clrscr(); int i,j,A[2][2]; int max_num; printf("\t\tThe Largest Element of a Matrix\n"); for(i=0;i<2;i++) for( j=0;j<2;j++) { printf("\nEnter A[%d][%d] : ",i,j); scanf("%d",&A[i][j]); } for(i=0;i<2;i++) { printf("\n"); for(j=0;j<2;j++) printf("%d\t",A[i][j]); } max_num=A[0][0]; for (i=0;i<2;i++) for( j=0;j<2;j++) { if (A[i][j]>=max_num) max_num=A[i][j]; } printf("\nMaximun number = %d",max_num); return max_num; }
int number(void)
{ int w; clrscr(); printf("Enter a number:"); fflush(stdin); scanf("%d",&w); return w;
}
int Question8(void)
{ clrscr(); float a,b; char ch= '+'||'-'|| '*' || '/'; printf("\t\tSimple Calculator\n"); printf("Enter operator either + or - or * or divide : "); printf("Enter statement : "); scanf("%d %c %d",&a,&ch,&b); switch (ch) { case '+': printf("Addition\t"); printf("%.1f +%.1f= %.1f",a,b,a+b); break; case '-': printf("Subtraction\t"); printf("%.1f - %.1f= %.1f",a,b,a-b); break; case '*': printf("Multiplication\t"); printf("%.1f * %.1f= %.1f",a,b,a*b); break; case '/': printf("Division\t"); printf("%.1f / %.1f= %.3f",a,b,a%b); break; default: printf("Error! operator is not correct"); break; } return c; }
void Question9() { clrscr(); int a,b; char ch;
printf("\t\tTable of Desired Number\n"); do { clrscr(); printf("Enter a number:"); a=number(); for (b=1;b<10;b++) { printf("%d * %d =%d\n",a,b,a*b); } printf("Press y/Y to continue..."); ch=getche(); } while (ch=='y' || ch=='Y'); getche(); }
int Question10()
{ clrscr(); int a,count=0;
printf("\t\tPrime Number\n"); printf("Enter a number : "); scanf("%d",&a);
for (int i=1;i<=a;i++) { if (a%i==0) count++; } if (count==2) printf("Number is Prime"); else printf("Not a Prime Number"); return a;
}
void Question11()
{ clrscr(); printf("\t\tFind & Replace any Character \n"); int a,b; char ch[80],c,d; printf("Enter a string: "); fflush(stdin); gets(ch); printf("\n"); printf("Which Character you wants to replace:"); scanf("%c",&c); printf("By which Character you wants to replace %c:",c); fflush(stdin); scanf("%c",&d); b=strlen(ch); for(a=0;a<b;a++) { if (ch[a]==c) printf("%c",d); else printf("%c",ch[a]); } printf("\nTotal words =%d\n",b); }
void Question12()
{ long int a=1,b=1; int i;
printf("\t\tFactorial of a number\n"); printf("Enter a Number :"); i=number(); printf("Factorial %d!",i); while (a<=i) { b=b*a; printf("\n%5ld\n",b); a++; } }
#include"head.h" void main(void)
{ clrscr(); for (int a=1;a<13;a++) printf("For Question # %d... Press %d\n",a,a); int ques; printf("\nEnter Your Choice:"); scanf("%d",&ques);
switch (ques) {
case 1: Question1(); break; case 2: Question2(); break; case 3: Question3(); break; case 4: Question4(); break; case 5: Question5(); break; case 6: Question6(); break; case 7: Question7(); break; case 8: Question8(); break; case 9: Question9(); break; case 10: Question10(); break; case 11: Question11(); break; case 12: Question12(); break;
} getche();
}