Posts

Showing posts from September, 2023

Compare 2 Strings in C

Compare two strings in C : #include < stdio.h > #include < string.h > #include < stdbool.h > int main () { char str1 [] = " ABC " ; char str2 [] = " ABC " ; bool res ; int i = 0 ; while ( str1 [ i ] != ' \0 ' && str2 [ i ] != ' \0 ' ) { if ( str1 [ i ] == str2 [ i ]) res = false ; else res = true ; i ++; } printf ( " %d \n " , res ); return 0 ; } Related Posts :  basic-input/output-c-program Check a Prime Number Array in C Swap 2 Numbers Loops in C Reverse String in C

Swap 2 Numbers in C

1. Swap 2 Numbers in C without using extra space or variable  #include < stdio.h > int main () { int a , b ; printf ( " Enter value of a and b " ); scanf ( " %d %d " , & a , & b ); printf ( " a and b before swap is = %d and %d \n " , a , b ); a = a + b ; b = a - b ; a = a - b ; printf ( " a and b after swap is = %d and %d \n " , a , b ); return 0 ; } 2. Swap 2 Numbers in C using extra variable #include < stdio.h > int main () { int a , b ; printf ( " Enter value of a and b " ); scanf ( " %d %d " , & a , & b ); printf ( " a and b before swap is = %d and %d \n " , a , b ); int c ; // temporary variable c = a ; a = b ; b = c ; printf ( " a and b after swap is = %d and %d \n " , a , b ); return 0 ; } Related Posts :  basic-input/output-c-program Array in C Check a Prime Number Loop...

Control structure in C

In C programming, loops are used to execute a block of code repeatedly as long as a certain condition is met. There are three main types of loops in C: for loop while loop do-while loop 1. for Loop : The for loop is commonly used when you know beforehand how many times you want to execute a block of code. It consists of three parts: initialization, condition, and increment/decrement. Example :-   #include < stdio.h > int main () { int i = 0 ; for ( i = 0 ; i < 10 ; i ++) { printf ( " Value of i is = %d \n " , i ); } for ( i = 10 ; i > 0 ; i --) { printf ( " Value of i is = %d \n " , i ); } return 0 ; } nested-for Loop : #include < stdio.h > int main () { int n ; printf ( " Enter the count number to print table \n " ); scanf ( " %d " ,& n ); printf ( " Entered number is = %d \n " , n ); for ( int i = 1 ; i <= n ; i ++) { for ( i...

Check Prime Number (C Program)

  C Program to check if a number is Prime or not : #include < stdio.h > #include < stdbool.h > int main () { int n ; bool prime ; printf ( " Enter the number \n " ); scanf ( " %d " , & n ); if ( n == 0 | n == 1 ) { printf ( " %d is not a Prime Number \n " , n ); return 0 ; } else { int i = 2 ; while ( i < n ) { if ( n % i == 0 ) { printf ( " %d is not a Prime Number \n " , n ); return 0 ; } i ++; } printf ( " %d is a Prime Number \n " , n ); } return 0 ; } Related Posts :  basic-input/output-c-program Array in C Swap 2 Numbers Loops in C Compare 2 Strings

Array in C

 Array in C Array : It is largely used data structure in C programming language. It is a contiguous storage of elements of same type of data type. So size of each element of an array will be same.  Total size of an array = (No. of elements) x (size of data-type) Normally Index of an array is start from zero. Therefore,  Index of 1st element  = 0 Index of last element = No. of elements in the array - 1 For example :- int arr[7];            // arr is an array of 7 integer elements First index of arr =  0 Last index of arr = 7-1 = 6 It is declared as shown below : data-type array-name[size of array]; e.g. :- int arr1[5]; // arr1 is an array of 5 integers float arr2[10]; //arr2 is an array of 10 floating numbers double arr3[10]; //arr3 is an array of 10 double type numbers An array element can be accessed using the index of that element in the array. Time Complexity of accessing an array element is O(1). A value can be added or mod...

QT Creator

QT Creator QT Creator is a cross-platform integrated development environment (IDE) with tools for designing and developing applications with Qt application framework. Qt Creator can be used as part of the software development process, as it integrates seamlessly with other Qt tools, or use it independently. C++ and Python can be used as programming Languages for development in Qt Creator. QT Creator runs on Windows, Linux, and macOS desktop operating systems. It allows developers to create applications once and run them on desktop, mobile, and embedded platforms. Compared to other IDE's, Qt Creator has following features :  Wizard templates for creating Qt and Qt Quick applications. A visual editor called Qt Designer for Qt Widgets, and an integrated workflow for creating Qt Quick applications with Qt Design Studio. Code editors that help you write good C++ and QML code. A locator for easily finding things in your project or code. Features for building and running your applications...