#include #include #include"loops.h" #include"operator.h" #include"conditional statement.h" #include"array.h" int main() { int choice; firstTopics: while(1) { printf("1.LOOP\n"); printf("2.CONDITIONAL STATEMENTS\n"); printf("3.OPERATOR\n"); printf("4.ARRAY\n"); printf("5.EXIT\n"); printf("Enter the choice between 1 to 5\n"); scanf("%d",&choice); switch(choice) { case 1:while(1) { printf("1.example program for for loop\n"); printf("2.example program for while loop\n"); printf("3.floyds triangle using loop\n"); printf("4.print rhombus pattern using loop\n"); printf("5.print A to I and 1 to 6 like right angled triangle\n"); printf("6.print stars using loop\n"); printf("7.find lcm and hcf using loop\n"); printf("8.print alphabets:\n"); printf("9.Last digit of a number\n"); printf("10.First digit of a number\n"); printf("11.Check polindrome or not\n"); printf("12.Find power of number\n"); printf("13.go to first topic\n"); printf("Enter choice between 1 to 13\n "); scanf("%d",&choice); switch(choice) { case 1:exampleProgramForForLoop();break; case 2:exampleProgramForWhileLoop();break; case 3:floydsTriangle();break; case 4:rombusPattern();break; case 5:printbelowPattern();break; case 6:usingLoopprintstars();break; case 7:findLcmAndHcfUsingLoop();break; case 8:printAlphabets();break; case 9:lastDigitOfANumber();break; case 10:firstDigitOfANumber();break; case 11:checkPolindromeOrNot();break; case 12:findPowerOfNumber();break; case 13:goto firstTopics;break; case 14:printf("invalid choice\n"); } } case 2:while(1) { printf("1.if statement example program\n"); printf("2.if else statement example program\n"); printf("3.if else if ladder example program\n"); printf("4.linear search\n"); printf("5.find day using switch\n"); printf("6.operators in switch case\n"); printf("7.nested switch case\n"); printf("8.checking vowel or not using switch case\n"); printf("9.maximum number between two\n"); printf("10.perfect root of the given number\n"); printf("11.find leap year\n"); printf("12.km convert into centi meter or meter\n"); printf("13.go to first topic\n"); printf("enter the choice between 1 to 13\n"); scanf("%d",&choice); switch(choice) { case 1:ifStatementExampleProgram();break; case 2:ifElseStatementExampleProgram();break; case 3: ifElseIfLaddeexampleProgram();break; case 4:LinearSearch();break; case 5:findDayUsingSwitchCase();break; case 6:operatornsInSwitchCase();break; case 7:nestedSwitchCase();break; case 8:checkingVowelOrNotUsingSwitchCase();break; case 9:maximumNumberBetweenTwoNum();break; case 10:perfectSquareRoot();break; case 11:findLeapYear();break; case 12:kmConvertToMetreCentiMeter();break; case 13:goto firstTopics ;break; default:printf("invalid choice\n"); } } case 3:while(1) { printf("1.Example program for arithmatic operator\n"); printf("2.Example program for logical operator\n"); printf("3.Example program for increment and decrement\n"); printf("4.Example program for relational operator\n"); printf("5.Example program for assignment operator\n"); printf("6.Example program for size of operator\n"); printf("7.Example program for shift operator\n"); printf("8.check number is prime or not\n"); printf("9.number of series and find some\n"); printf("10.to add numbers unstill user enter zero\n"); printf("11.go to first topic\n "); printf("enter the choice between 1 to 11\n "); scanf("%d",&choice); switch(choice) { case 1:arithmaticOperator();break; case 2:logicalOperator();break; case 3:incrementAndDecrement();break; case 4:relationalOperator();break; case 5:assignmentOperator();break; case 6:sizeOfOperator();break; case 7:shiftOperator();break; case 8:checkNumberPrimeOrNot();break; case 9:sumOfSeriesOfFraction();break; case 10:toAddNumbersUntillTheUserEntersZero();break; case 11:goto firstTopics;break; default:printf("invalid choice\n"); } } case 4:while(1) { printf("1.Sum of array\n"); printf("2.Find largest element in an array element\n"); printf("3.Find smallest element in an array element\n"); printf("4.Find average Of an array element\n"); printf("5.Covert number to decimal to octal numbers\n"); printf("6.Find even and odd number 0f the array elements\n"); printf("7.Reverse order of an array elements\n"); printf("8.Number of zeroes in an array elements\n"); printf("9.Sum and subtract of matrix elements\n"); printf("10.Printing array elements\n"); printf("11.Deleting element from an array\n"); printf("12.Sorting of an element using 3 rows and 3 column\n"); printf("13.Tranpose of matrix using array\n"); printf("14.Structure demo using different data types Of array\n"); printf("15.Trace of matrix using two dimensional array\n"); printf("16.Norm of matrix using two dimensional array\n"); printf("17.Address of matrix elements\n"); printf("18.Finding a string length of an array\n"); printf("19.Swapping of two array elements\n"); printf("20.No of zeros,positive and negative\n"); printf("21.Sum diagonal elements\n"); printf("22.Acending and descending order in array\n"); printf("23.Copying array elements from another array\n"); printf("24.Second largest element in an array\n"); printf("25.Multiplication of an array\n"); printf("26.go to first topic\n"); printf("Enter choice between 1 to 26\n"); scanf("%d",&choice); switch(choice) { case 1:sumofarray();break; case 2:findLargestOfArrayElement();break; case 3:findSmallestOfArrayElement();break; case 4:findaverageOfArrayElement();break; case 5:covertNumberDecimalToOctal();break; case 6:findEvenAndOddOfTheArrayElements();break; case 7:reverseOrderOfArrayElements();break; case 8:noOfZeroesInArrayElements();break; case 9:sumAndSubOfMatrixOfArrayElements();break; case 10:printingArrayElements();break; case 11:deletingElementInArray();break; case 12:sortElementUsing3RowsAnd3col();break; case 13:tranposeOfMatrixUsingArray();break; case 14:structureDemoUsingDifferentDatatypesOfArray();break; case 15:traceOfMatrixUsingTwoDimensionalArray();break; case 16:normOfMatrixUsingTwoDimensionalArray();break; case 17:addressOfMatrixElements();break; case 18:stringLength();break; case 19:swappingOfTwoArrayElements();break; case 20:noOfZerozPositiveAndNegative();break; case 21:diagonalElementsSum();break; case 22:acendingAndDescendingOrderInArray();break; case 23:copyArrayElementsToAnotherArray();break; case 24:secondLargestInAnArray();break; case 25:multiplicationOfArray();break; case 26:goto firstTopics;break; default:printf("Enter the correct choice\n");break; } } case 5:exit(0); } } } loops// void exampleProgramForForLoop() { int i; printf("print number from 1 to 10\n\n"); for(i=1;i<=10;i++) { printf("%d\n",i); } } void exampleProgramForWhileLoop() { int num=200; printf("print numbers from 200 to 400\n\n"); while(num<=400) { printf("%d\n",num); num++; } printf("*******************\n\n"); } void floydsTriangle() /*Floyd's triangle 1 2 3 4 5 6 7 8 9 1*/ { int i,j,r,k=1; printf("Enter the range: "); scanf("%d",&r); printf("FLOYD'S TRIANGLE\n\n"); for(i=1;i<=r;i++) { for(j=1;j<=i;j++,k++) { printf(" %d",k); } printf("\n\n"); } } void rombusPattern() { /* Rhombus Pattern 1 1 2 2 3 3 4 4 3 3 2 2 1 1 */ int num,i,c,s,n; printf("Enter maximum number : "); scanf("%d", &num); for(i=1; i<=num; i++) { for(s=num-i; s>=1; s--) printf(" "); printf("%d", i); for(s=i*2; s>1; s--) printf(" "); printf("%d", i); printf("\n"); } for(i=1,n=num-1; i=1; s--) printf(" "); printf("%d",n); for(s=n*2; s>1; s--) printf(" "); printf("%d", n); printf("\n"); } } void printbelowPattern() { /* Print Pattern A 1 2 B C D 3 4 5 6 E F G H I */ int i,n,j,k=1; char ch='A'; printf("\n\nEnter How Many Rows Own::>\n"); scanf("%d",&n); for(i=1;i<=n;i++) { if((i%2)==0) { for(j=1;j<=i;j++) { printf("%d",k); k++; } } else { for(j=1;j<=i;j++) { printf("%c",ch); ch++; } } printf("\n"); } } void usingLoopprintstars() { /*-- ********** *** *** *** ** ** ** * * * * * * ** ** ** *** *** *** ********** --*/ int i, j, k; for(i=1;i<=5;i++) { for(j=1;j<=6-i;j++) { printf("*"); } for(k=1;k b) g = a; else g = b; for(i=g ; i<=(a*b) ; i++) { if((i%a == 0) && (i%b == 0)) { lcm = i; break; } } printf( "\n The LCM of given Numbers is = %d\n", lcm ); hcf = (a * b) / lcm; printf( "\n The HCF of given Numbers is = %d\n", hcf ); } void printAlphabets() { char ch; printf("Alphabets from a - z are: \n"); for(ch='a'; ch<='z'; ch++) { printf("%c\n", ch); } return 0; } void lastDigitOfANumber() { int n, lastDigit; /* Input number from user */ printf("Enter any number: "); scanf("%d", &n); /* Get the last digit */ lastDigit = n % 10; printf("Last digit = %d\n", lastDigit); return 0; } void firstDigitOfANumber() { int n, first; /* Input number from user */ printf("Enter any number: "); scanf("%d", &n); first = n; /* Remove last digit from number till only one digit is left */ while(first >= 10) { first = first / 10; } printf("First digit = %d\n", first); return 0; } void checkPolindromeOrNot() { int n, num, rev = 0; /* Input a number from user */ printf("Enter any number to check palindrome: "); scanf("%d", &n); /* Copy original value to 'num' to 'n'*/ num = n; /* Find reverse of n and store in rev */ while(n != 0) { rev = (rev * 10) + (n % 10); n /= 10; } /* Check if reverse is equal to 'num' or not */ if(rev == num) { printf("%d is palindrome.\n", num); } else { printf("%d is not palindrome.\n", num); } return 0; } void findPowerOfNumber() { int base, exponent; long long power = 1; int i; /* Input base and exponent from user */ printf("Enter base: "); scanf("%d", &base); printf("Enter exponent: "); scanf("%d", &exponent); /* Multiply base, exponent times*/ for(i=1; i<=exponent; i++) { power = power * base; } printf("%d ^ %d = %lld", base, exponent, power); return 0; } operator void arithmaticOperator() { int a,b; printf("Enter the value for a and b:\n"); scanf("%d%d",&a,&b); int sum, sub, mul, rem, idiv ; float rdiv; sum = a + b; sub = a - b; mul = a * b; idiv = a / b; rem = a % b; rdiv = (float)a / (float)b; printf( "\n sum = %d", sum ); printf( "\n sub = %d", sub ); printf( "\n mul = %d", mul ); printf( "\n idiv = %d", idiv ); printf( "\n rem = %d", rem ); printf( "\n rdiv = %f", rdiv ); } void logicalOperator() { int a ,b,c,result; printf("Enter number for a,b and c\n"); scanf("%d%d%d",&a,&b,&c); result = (a == b) && (c > b); printf("(a == b) && (c > b) is %d \n", result); result = (a == b) && (c < b); printf("(a == b) && (c < b) is %d \n", result); result = (a == b) || (c < b); printf("(a == b) || (c < b) is %d \n", result); result = (a != b) || (c < b); printf("(a != b) || (c < b) is %d \n", result); result = !(a != b); printf("!(a != b) is %d \n", result); result = !(a == b); printf("!(a == b) is %d \n", result); return 0; } void incrementAndDecrement() { int a = 10, b = 100; float c = 10.5, d = 100.5; printf("++a = %d \n", ++a); printf("--b = %d \n", --b); printf("++c = %f \n", ++c); printf("--d = %f \n", --d); } void relationalOperator() { int n; printf( "\n Enter any Number : " ); scanf( "%d", &n ); printf( "\n (n < 10) is = %d", (n < 10) ); printf( "\n (n > 10) is = %d", (n > 10) ); printf( "\n (n <= 10) is = %d", (n <= 10) ); printf( "\n (n >= 10) is = %d", (n >= 10) ); printf( "\n (n == 10) is = %d", (n == 10) ); printf( "\n (n != 10) is = %d", (n != 10) ); } void assignmentOperator() { int a,c; printf("Enter the number for a\n"); scanf("%d",&a); c = a; // c is 5 printf("c = %d\n", c); c += a; // c is 10 printf("c = %d\n", c); c -= a; // c is 5 printf("c = %d\n", c); c *= a; // c is 25 printf("c = %d\n", c); c /= a; // c is 5 printf("c = %d\n", c); c %= a; // c = 0 printf("c = %d\n", c); } void sizeOfOperator() { int a; float b; double c; char d; printf("Size of int=%lu bytes\n",sizeof(a)); printf("Size of float=%lu bytes\n",sizeof(b)); printf("Size of double=%lu bytes\n",sizeof(c)); printf("Size of char=%lu byte\n",sizeof(d)); } void shiftOperator() { int num, i; printf("Enter number for shift\n"); for (i=0; i<=2; ++i) printf("Right shift by %d: %d\n", i, num>>i); printf("\n"); for (i=0; i<=2; ++i) printf("Left shift by %d: %d\n", i, num<0) { printf("given number is positive\n"); } else { printf("given number is negative\n"); } } void ifElseIfLaddeexampleProgram() { int num1,num2,num3; printf("Enter the values for num1,num2,num3\n"); scanf("%d%d%d",&num1,&num2,&num3); if(num1>num2 & num1>num3) { printf("%d is greater\n",num1); } else if(num2>num3) { printf("%d is greater\n",num2); } else { printf("%d is greater\n",num3); } } void LinearSearch() { int array[50],search,c,n; printf("enter the element\n"); scanf("%d",&n); printf("enter %d elements:\n"); for(c=0;c>\n"); scanf("%d",&day); switch(day) { case 1: { printf("Monday"); break; } case 2: { printf("Tuesday"); break; } case 3: { printf("Wednesday"); break; } case 4: { printf("Thursday"); break; } case 5: { printf("Friday"); break; } case 6: { printf("Saturday"); break; } case 7: { printf("Sunday"); break; } default: { printf("Invalid day number"); } } printf("\nHave a nice day"); } void operatornsInSwitchCase()// Operator as case in switch case { char op; float num1,num2,res; printf("Enter first number:>>\n"); scanf("%f",&num1); printf("Enter second number:>>\n"); scanf("%f",&num2); printf("Operation(+,-,*,/):>>\n"); fflush(stdin); scanf("%c",&op); switch(op) { case '+': { res=num1+num2; break; } case '-': { res=num1-num2; break; } case '*': { res=num1*num2; break; } case '/': { res=num1/num2; break; } default: { printf("Invalid choice..."); } } printf("Result::%f",res); } void nestedSwitchCase() { int choice,ch1,ch2; printf("\n1.Pen \n2.Fruits"); printf("\nEnter value of choice:>>"); scanf("%d",&choice); switch(choice) { case 1: { printf("\n1.Micro \n2.Renold \n3.Cello:"); printf("\nEnter the value of Ch1:>>\n"); scanf("%d",&ch1); switch(ch1) { case 1: { printf("\nMicro"); break; } case 2: { printf("\nRenold"); break; } case 3: { printf("\nCello"); break; } default: { printf("Invalid case"); } } break; } case 2: { printf("\n1.Mango \n2.Orange \n3.Pineple"); printf("Enter the value of Ch2:>>\n"); scanf("%d",&ch2); switch(ch2) { case 1: { printf("\nMango"); break; } case 2: { printf("\nOrange"); break; } case 3: { printf("\nPineple"); break; } default: { printf("Invalid case"); } } break; } default: { printf("Invalid Choice"); } } } void checkingVowelOrNotUsingSwitchCase() { char ch; printf(" Enter any Character : " ); getchar(); scanf("%c",&ch); switch( ch ) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U':printf( "\n %c is Vowel.", ch );break; default : printf( "\n %c is not a Vowel.", ch ); break; } } void maximumNumberBetweenTwoNum() { int a,b,max; printf("Enter two numbers : "); scanf("%d%d",&a,&b); if(a > b) max = a; else max = b; printf("Max is %d\n",max); return 0; } void perfectSquareRoot() { int n,a; printf("Enter the value of N:\n"); scanf("%d",&n); a=sqrt(n); if(n-(a*a)==0) printf("\n\n\nIt is perfect squre"); else printf("\n\n\nIt is not perfect squre\n"); } void findLeapYear() { int year; printf("Enter a year : \n"); scanf("%d", &year); if ( year%400 == 0) { printf("%d is a leap year.\n", year); } else if ( year%100 == 0) { printf("%d is not a leap year.\n", year); } else if ( year%4 == 0 ) { printf("%d is a leap year.\n", year); } else { printf("%d is not a leap year.\n", year); } } void kmConvertToMetreCentiMeter() { float km; int v; float ans; printf("Enter distance in K.M. :\n "); scanf("%f",&km); printf("1 for meter 2 for centimeter 3 for mm : "); scanf("%d",&v); if(v==1) { ans=km*1000; } if(v==2) { ans=km*100000; } if(v==3) { ans=km*1000000; } printf("Answer : %.2f",ans); } array// void sumofarray() { printf("Sum of array\n"); int i,a[10],sumofarray=0; for(i=0;i<10;i++) { a[i]=i+1; } for(i=0;i<10;i++) { sumofarray=sumofarray+a[i]; } printf("%d\n",sumofarray); } void findLargestOfArrayElement() { int a[10],limit,largest,i; printf("Enter the no array elements you want:"); scanf("%d",&limit); printf("Enter %d elements\n",limit); for(i=0;i largest) { largest = a[i]; } } printf("Largest of array is %d\n",largest); } void findSmallestOfArrayElement() { int a[10],limit,smallest,i; printf("Enter the no array elements you want:"); scanf("%d",&limit); printf("Enter %d elements\n",limit); for(i=0;i 0; j--) printf("%d", octalNumber[j]); } void findEvenAndOddOfTheArrayElements() { int arr1[10], arr2[10], arr3[10]; int i,j=0,k=0,n; printf("Input the number of elements to be stored in the array :"); scanf("%d",&n); printf("Input %d elements in the array :\n",n); for(i=0;i=0;i=i-1) { printf("%d\n",a[i]); } } void noOfZeroesInArrayElements() { int a[10],limit,i,numOfZeros=0; printf("Enter the limit of array\n"); scanf("%d",&limit); printf("Enter %d elements\n",limit); for(i=0;ia[i][k]) { temp=a[i][j]; a[i][j]=a[i][k]; a[i][k]=temp; } } } } printf("\nRow by row sorted\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } printf("\n"); } } void tranposeOfMatrixUsingArray() { int a[10][10], transpose[10][10], r, c; printf("Enter rows and columns: "); scanf("%d %d", &r, &c); // asssigning elements to the matrix printf("\nEnter matrix elements:\n"); for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) { printf("Enter element a%d%d: ", i + 1, j + 1); scanf("%d", &a[i][j]); } // printing the matrix a[][] printf("\nEntered matrix: \n"); for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) { printf("%d ", a[i][j]); if (j == c - 1) printf("\n"); } // computing the transpose for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) { transpose[j][i] = a[i][j]; } // printing the transpose printf("\nTranspose of the matrix:\n"); for (int i = 0; i < c; ++i) for (int j = 0; j < r; ++j) { printf("%d ", transpose[i][j]); if (j == r - 1) printf("\n"); } } void structureDemoUsingDifferentDatatypesOfArray() { struct Student { char name[10]; char usn[10]; char degree[5]; int sem; float avg; }; struct Student s1,s2; printf("Size of s1:%d\n",sizeof(s1)); printf("Size of s2:%d\n",sizeof(s2)); } void traceOfMatrixUsingTwoDimensionalArray() { int matrix[10][10],row,col,rowLimit,colLimit,trace,norm,sum = 0,squareOfInputElement,sumofsquare = 0; printf("Enter the no of rows and cols you want.?\n"); scanf("%d%d",&rowLimit,&colLimit); printf("Enter the %d elements\n",rowLimit*colLimit); for(row = 0;row\n"); for(i=0;i<5;i++) scanf("%d",&a[i]); printf("Enter Second array->\n"); for(i=0;i<5;i++) { scanf("%d",&b[i]); } printf("\nArrays before swapping"); printf("\nFirst array->"); for(i=0;i<5;i++) { printf("%d",a[i]); } printf("\nSecond array->"); for(i=0;i<5;i++){ printf("%d",b[i]); } for(i=0;i<5;i++) { //write any swapping technique c[i]=a[i]; a[i]=b[i]; b[i]=c[i]; } printf("Arrays after swapping\n"); printf("First array->\n"); for(i=0;i<5;i++){ printf("%d\n",a[i]); } printf("Second array->\n"); for(i=0;i<5;i++){ printf("%d\n",b[i]); } } void noOfZerozPositiveAndNegative() { int m[10],i,pos=0,neg=0,zero=0,n; printf("How many numbers ?"); scanf("%d",&n); printf("\nEnter %d integer elements \n",n); for(i=0;i0) { pos++; } else if(m[i]<0) { neg++; } else { zero++; } } printf("\npositive elements=%d\n",pos); printf("\nnegative elements=%d\n",neg); printf("\nzero elements=%d\n",zero); } void diagonalElementsSum() { int a[10][10],i,j,sum=0,m,n; printf("\nEnter the row and column of matrix: \n"); scanf("%d%d",&m,&n); printf("\nEnter the elements of matrix: \n"); for(i=0;iarr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } printf("\n-------------------------------------------"); printf("\n Original\tAccending\tDescending"); printf("\n-------------------------------------------"); for(i=0,j=9;i<10;i++,j--) { printf("\n%d\t\t%d\t\t%d",tmp[i],arr[i],arr[j]); } printf("\n-------------------------------------------"); printf("\n\n\n press any key-----"); } void copyArrayElementsToAnotherArray() { int arr1[30], arr2[30], i, num; printf("\nEnter no of elements:\n"); scanf("%d", &num); //Accepting values into Array printf("\nEnter the values:\n"); for (i = 0; i < num; i++) { scanf("%d", &arr1[i]); } for (i = 0; i < num; i++) { arr2[i] = arr1[i]; } //Printing of all elements of array printf("The copied array is:\n"); for (i = 0; i < num; i++) printf("\n arr2[%d] = %d\n", i, arr2[i]); } void secondLargestInAnArray() { int arr[100],i,n,sec_largest; printf("Enter the size of the array?\n"); scanf("%d",&n); printf("Enter the elements of the array\n?"); for(i = 0; isec_largest) { sec_largest=arr[i]; } } printf(" second largest = %d\n",sec_largest); } void multiplicationOfArray() { int first[5][5],second[5][5],result[5][5],row1,col1,row2,col2,rowCounter,colCounter,k; printf("Enter the first matrix row and column limit\n"); scanf("%d%d",&row1,&col1); printf("Enter first matrix %d elements\n",row1*col1); for(rowCounter=0;rowCounter