Arduino Tutorial for Beginners – Arduino Strings and Loops
In this post on Arduino Tutorial For Beginners, this topic about Strings and Loops + Loops, we have two common […]
C, tutorial, beginners, programming, ANSI, simple, examples, language basics, literals, data types, functions, loops, arrays, pointers, structures, input and output, memory management, pre-processors, directives.
In this post on Arduino Tutorial For Beginners, this topic about Strings and Loops + Loops, we have two common […]
In this post on Arduino Tutorial For Beginners, We’ve already known how to make an output and control led on […]
In this post on Arduino Tutorial For Beginners, this topic about Serial Port on Arduino and Serial Monitor on Arduino IDE. About […]
SQLite C/C++ – CREATE Table in SQLite Database using C/C++ SQLite C/C++- CREATE Table in SQLite Database using C/C++ […]
SQLite C/C++- CREATE and OPEN SQLite Database using C/C++ Make a C Program file and Name it as main.c […]
MinGW, a contraction of “Minimalist GNU for Windows”, is a minimalist development environment for native Microsoft Windows applications. Downloading MinGW open […]
The C program below will create a file , open the same file, and write in it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/** C program to create a file and write to same file C program to open a file by Codebind.com */ #include <stdio.h> int main() { int num; FILE *fptr; fptr = fopen("program.txt","w"); if(fptr == NULL) { printf("Error!"); return 1; } printf("Enter a number to save it in a file: "); scanf("%d",&num); fprintf(fptr,"%d",num); fclose(fptr); return 0; } /* OUTPUT Enter a number to save it in a file: 5555555555555555555555555555555555555555555 */ |
The base 8 number system is known as octal we’ll look at number conversions. C Program to Convert Decimal to […]
Decimal to Binary Converter in C using inbuilt function itoa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/********************************************************************** Decimal to binary in c **********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <conio.h> int main(int argc, char** argv) { int number; char binary [10]; printf("Enter a decimal number:"); scanf("%d",&number); printf("\n"); itoa(number, binary, 2); printf("\nBinary conversion of %d : %s", number, binary); getch(); return 0; } /* OUTPUT: Enter a decimal number:7 Binary conversion of 7 : 111 */ |
Decimal to Binary Converter in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/********************************************************************** Decimal to binary in c **********************************************************************/ #include<stdio.h> int main(){ long int decimalNumber, quotient; int binaryNumber[100],i=1,j; printf("Enter a decimal number: "); scanf("%ld",&decimalNumber); quotient = decimalNumber; while(quotient!=0){ binaryNumber[i++]= quotient % 2; quotient = quotient / 2; } printf("Binary conversion of %d : ",decimalNumber); for(j = i -1 ;j> 0;j--) printf("%d",binaryNumber[j]); return 0; } /* OUTPUT: Enter a decimal number:7 Binary conversion of 7 : 111 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/********************************************************************** HCF (Highest common factor) program with two numbers in c **********************************************************************/ #include<stdio.h> int main(){ int number_1,number_2; printf("\nEnter two numbers:"); scanf("%d %d",&number_1,&number_2); while(number_1!=number_2){ if(number_1>=number_2-1) number_1=number_1-number_2; else number_2=number_2-number_1; } printf("\nGCD=%d",number_1); return 0; } /* OUTPUT: Enter two numbers:3 12 GCD=3 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/********************************************************************** GCD Using for loop and if Statement using C Program **********************************************************************/ #include <stdio.h> int main() { int number_1, number_2, i, gcd; printf("Enter two integers: "); scanf("%d %d", &number_1, &number_2); for(i=1; i <= number_1 && i <= number_2; ++i) { // Checks if i is factor of both integers if(number_1%i==0 && number_2%i==0) gcd = i; } printf("G.C.D of %d and %d is %d", number_1, number_2, gcd); return 0; } /* OUTPUT: Enter two integers: 12 3 G.C.D of 12 and 3 is 3 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/********************************************************************** LCM using while Loop and if Statement using C Program **********************************************************************/ #include <stdio.h> int main() { int number_1, number_2, minMultiple; printf("Enter two positive integers: "); scanf("%d %d", &number_1, &number_2); // maximum number between number_1 and number_2 is stored in minMultiple minMultiple = (number_1 > number_2) ? number_1 : number_2; // Always true while(1) { if( minMultiple%number_1==0 && minMultiple % number_2==0 ) { printf("The LCM of %d and %d is %d.", number_1, number_2,minMultiple); break; } ++minMultiple; } return 0; } /* OUTPUT: Enter two positive integers: 11 12 The LCM of 11 and 12 is 132 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/********************************************************************** How to Get power of number in c **********************************************************************/ #include<stdio.h> int main(){ int power, number, i = 1; long int sum = 1; printf("\nEnter a number : "); scanf("%d",&number); printf("\nEnter power : "); scanf("%d",&power); while(i<=power){ sum = sum * number; i++; } printf("\n%d to the powerer %d is: %ld",number, power, sum); return 0; } /* OUTPUT: Enter a number : 11 Enter power : 2 11 to the powerer 2 is: 121 */ |
C program to reverse the digits of a number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/********************************************************************** 1. Reverse of a number in c using while loop 2. C program to reverse the digits of a number 3. Write a c program to reverse a given number 4. C program to find reverse of a number **********************************************************************/ #include<stdio.h> int main(){ int number; int r; int reverse = 0; printf("Enter a number: "); scanf("%d", &number); while(number){ r=number%10; reverse=reverse*10+r; number=number/10; } printf("Reversed number is : %d",reverse); return 0; } /* OUTPUT: Enter a number: 987654321 Reversed number is : 123456789 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/********************************************************************** C Program to calculate frequency of vowels in a string **********************************************************************/ #include <stdio.h> #include <conio.h> void main() { int a=0,e=0,i=0,o=0,u=0,sum=0; char c; printf("Enter string:- "); printf("\nString will be terminated if you press Ctrl-Z & then ENTER."); printf("\nSTRING:- "); while ((c=getchar())!=EOF) { if (c=='a'||c=='A') a=a+1; if (c=='e'||c=='E') e=e+1; if (c=='i'||c=='I') i=i+1; if (c=='o'||c=='O') o=o+1; if (c=='u'||c=='U') u=u+1; } sum=a+e+i+o+u; printf("\nFrequency of vowel 'a' is %d.",a); printf("\nFrequency of vowel 'e' is %d.",e); printf("\nFrequency of vowel 'i' is %d.",i); printf("\nFrequency of vowel 'o' is %d.",o); printf("\nFrequency of vowel 'u' is %d.",u); printf("\nTotal no. of vowels in the text is %d.",sum); } /* OUTPUT: Enter string:- String will be terminated if you press Ctrl-Z & then ENTER. STRING:- weghwehfgwwwpqezrhdnxmy,aldhfbvgctesvdchxmakwqpriuzttrewqasdgfhjklmynxc Frequency of vowel 'a' is 3. Frequency of vowel 'e' is 5. Frequency of vowel 'i' is 1. */ |
Copyright © 2021 | WordPress Theme by MH Themes