1. I'm wondering how to compile this 3 source code in 1 program using case statement coz im having difficult to make it in 1 combined program..
i hope somebody could help me thanks ...
example :
[1] Sound
[2] Fibonacci numbers
[3] Multiplication of Matrices
please select a number:
1st code: Sound
2nd code: Fibonacci numbersCode:#include <dos.h> #include <stdio.h> #include <stdlib.h> int menu(void); main() { while(1) { /*get selection and execute the relevant statement*/ switch(menu()) { case 1: { puts("sound the speaker 1\n"); sound(2000); sleep(2); nosound(); break; } case 2: { puts("sound that speaker 2\n"); sound(4000); sleep(2); nosound(); break; } case 3: { puts("You are quitting\n"); exit(0); break; } default: { puts("Invalid menu choice\n"); break; } } } return 0; } /*menu function*/ int menu(void) { int reply; /*display menu options*/ puts("Enter 1 for beep 1.\n"); puts("Enter 2 for beep 2.\n"); puts("Enter 3 to quit.\n"); /*scan for user entry*/ scanf("%d", &reply); return reply; }
3rd Code: Multiplication of MatricesCode:#include <stdio.h> int main(void) { int n; /* The number of fibonacci numbers we will print */ int i; /* The index of fibonacci number to be printed next */ int current; /* The value of the (i)th fibonacci number */ int next; /* The value of the (i+1)th fibonacci number */ int twoaway; /* The value of the (i+2)th fibonacci number */ printf("How many Fibonacci numbers do you want to compute? "); scanf("%d", &n); if (n<=0) printf("The number should be positive.\n"); else { printf("\n\n\tI \t Fibonacci(I) \n\t=====================\n"); next = current = 1; for (i=1; i<=n; i++) { printf("\t%d \t %d\n", i, current); twoaway = current+next; current = next; next = twoaway; } } return 0; } /* The output from a run of this program was: How many Fibonacci numbers do you want to compute? 9 I Fibonacci(I) ===================== 1 1 2 1 3 2 4 3 5 5 6 8 7 13 8 21 9 34 */
Code:#include<stdio.h> #include<conio.h> void main() { int mat1[2][2],mat2[2][2],mat3[2][2],i,j,k; clrscr(); printf("************A program to find the multiplication of the given matrices***********\n\n"); printf("************Enter the value for the 1st matrix************\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { printf("\nEnter the value for %d row,%d column:",i+1,j+1); scanf("%d",&mat1[i][j]); } } printf("\n************Enter the value for the 2nd matrix************\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { printf("\nEnter the value for %d row,%d column:",i+1,j+1); scanf("%d",&mat2[i][j]); } } printf("\n****************************The given matrices are*****************************\n\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { printf("%d\t",mat1[i][j]); } printf("\n"); } printf("\n\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { printf("%d\t",mat2[i][j]); } printf("\n"); } printf("\n****************************The multiplication of the matrices is*************\n\n"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { mat3[i][j]=0; for(k=0;k<2;k++) { mat3[i][j]=mat3[i][j]+(mat1[i][k]*mat2[k][j]); } } } for(i=0;i<2;i++) { for(j=0;j<2;j++) { printf("%d\t",mat3[i][j]); } printf("\n"); } getch(); getch(); }



LinkBack URL
About LinkBacks


