C Tutorials

nested for loop in c 0

Nested For Loop in C with Examples

Loops allow us to repeatedly execute code in an efficient manner. They form an integral part of programming across languages. In C, we have tools like the humble for loop to perform repetitive tasks....

C Program For malloc() and calloc() Function 0

C Program For malloc() and calloc() Function

Program 1 //Diffrence between malloc and calloc function for Dynamic memory #include<stdio.h> #include<stdlib.h> #include<conio.h> void main() { int *ar,n,i; printf(“%d”,sizeof(int)); printf(“Enter the limit”); scanf(“%d”,&n); ar= (int*)calloc(sizeof(int),n); // n block of 4 size printf(“Enter elements...

C Program to Convert Binary to Octal 0

C Program to Convert Binary to Octal

Program 1 // Program for Binary to decimal and decimal to octal #include<stdio.h> #include<conio.h> #define clrscr() system(“cls”) int main() { int n,dn=0,r,b=1,binary,i=0,ar[50]; clrscr(); printf(“Enter a binary number( only 0 and 1 format)”); scanf(“%d”,&n); binary=n;...

C Program to Convert Binary to Hexadecimal 0

C Program to Convert Binary to Hexadecimal

Program 1 // Program for Binary to hexa decimal #include<stdio.h> #include<conio.h> #define clrscr() system(“cls”) int main() { int n,dn=0,r,b=1,binary,i=0,ar[50]; clrscr(); printf(“Enter a binary number( only 0 and 1 format)”); scanf(“%d”,&n); binary=n; while(n!=0) { r=n%10;...

C Program to Convert Binary to Decimal 0

C Program to Convert Binary to Decimal

Program 1 // Program for Binary to decimal and decimal to octal #include<stdio.h> #include<conio.h> #define clrscr() system(“cls”) int main() { int n,dn=0,r,b=1,binary,i=0,ar[50]; clrscr(); printf(“Enter a binary number( only 0 and 1 format)”); scanf(“%d”,&n); binary=n;...

C Program to Find ASCII Value of a Character 0

C Program to Find ASCII Value of a Character

Program 1 #include<stdio.h> #define clrscr() system(“cls”) int main() { int i; char ch; clrscr(); printf(“\n Character \t Ascii Values”); for(i=0;i<=255;i++) { ch=i; // implicit type conversion printf(“\n%c\t %d”,ch,i); } return 0; }  

C Project – Guess a Random Number in with Source Code 0

C Project – Guess a Random Number in with Source Code

Program 1 #include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int me,you,count=5,i=1,f=0; system(“cls”); srand(time(NULL)); me=rand()%100; //printf(“%d”,me); while(i<=5) { printf(“\n Enter a number for guess.. you left %d chance”,count); scanf(“%d”,&you); if(me==you) { printf(“\n\nGreat… You win game is...

How to Generate Random Numbers in C using rand() and srand() Function 0

How to Generate Random Numbers in C using rand() and srand() Function

Program 1 #include<stdio.h> #include<conio.h> #include<time.h> int main() { int n,i,l,u; system(“cls”); srand(time(NULL)); printf(“Enter lower value of Random Number”); scanf(“%d”,&l); printf(“Enter upper value of Random Number”); scanf(“%d”,&u); for(i=1;i<=5;i++) { n=(rand() %(u-l+1)) + l; printf(“%5d”,n); }...