C Tutorials

How to Create Your Own Command in C 0

How to Create Your Own Command in C

Program 1 #include<stdio.h> #include<conio.h> int main(int argc,char *argv[]) { if(argc==2) { FILE *fp=NULL; fp=fopen(argv[1],”r”); if(fp==NULL) printf(“File not found”); else { char ch; while(((ch=fgetc(fp))!=EOF)) { printf(“%c”,ch); } fclose(fp); } } else printf(“Invalid command….”); }  

C Dynamic Memory Allocation 0

C Dynamic Memory Allocation

Program 1 // Dynamic Memory in C #include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { system(“cls”); int *ar=NULL; int n,i; printf(“Enter the limit: “); scanf(“%d”,&n); //ar=(int*)(malloc(sizeof(int)*n)); ar=(int*)(calloc(sizeof(int),n)); printf(“Enter an elements: “); for(i=0;i<n;i++) scanf(“%d”,&ar[i]); for(i=0;i<n;i++) printf(“\n%d”,ar[i]); int...

C Program to Find Largest and Smallest Element in an Array 0

C Program to Find Largest and Smallest Element in an Array

Program 1 //Largest element from array #include<stdio.h> #include<conio.h> int main() { system(“cls”); int ar[500],n,i,max,pos; printf(“\n Enter the limit:”); scanf(“%d”,&n); printf(“Enter elements in array:\n”); for(i=0;i<n;i++) scanf(“%d”,&ar[i]); max=ar[0]; //max=0; pos=0; for(i=1;i<n;i++) { if(ar[i]>max) { max=ar[i]; pos=i;...

Local and Global Variables in C 0

Local and Global Variables in C

Program 1 // Local and global variables #include<stdio.h> #include<conio.h> int main() { system(“cls”); int a=10; { int a=20; { int a=30; { int a=40; printf(“\n %d”,a); } printf(“\n %d”,a); } printf(“\n %d”,a); } printf(“\n...

Call by Value and Return by Value in C 0

Call by Value and Return by Value in C

Program 1 #include<stdio.h> #include<conio.h> int swap(int a,int b); int main() { int a,b; // local system(“cls”); printf(“Enter two number”); scanf(“%d %d”,&a,&b); printf(“\nBefore swaping %d %d”,a,b); a,b=swap(a,b); printf(“\nAfter swaping %d %d”,a,b); } int swap(int a,int...

C Break and Continue 0

C Break and Continue

Program 1 // Break and continue Statement #include<stdio.h> #include<conio.h> int main() { system(“cls”); int i; for(i=1;i<=50;i++) { if(i%2==0) continue; printf(“%d\n”,i); } // int i,j,n,s,flag=0; // int a[10]; // printf(“Enter 10 elements in array”); //...

Goto Statement in C 0

Goto Statement in C

Program 1 // Goto Statement in C #include<stdio.h> #include<conio.h> int main() { system(“cls”); printf(“\nHello”); goto abc; printf(“\nIndore”); printf(“\nBhopal”); abc: printf(“\nBye Bye”); // int h,m,e,c,total,per; // system(“cls”); // hindi:printf(“\nEnter marks of hindi: “); // scanf(“%d”,&h);...

C Do While Loop 0

C Do While Loop

Program 1 #include<stdio.h> #include<conio.h> int main() { int choice; system(“cls”); do { printf(“\n——————Menu———————–“); printf(“\n 1.Factorial\n 2.Reverse \n 3. Power \n 4.Exit”); printf(“\n———————————————–“); printf(“\nEnter your choice”); scanf(“%d”,&choice); switch(choice) { case 1: { int n,f=1; printf(“\nEnter...

C Logical Operators 0

C Logical Operators

Program 1 // Logical operators in C // && || ! #include<stdio.h> #include<conio.h> int main() { system(“cls”); int a,b,c; a=500,b=10; c=!a; printf(“%d”,c); // c= !(a>100 && b<20); // printf(“%d”,c); // int per; // char...

C Escape Sequence 0

C Escape Sequence

Program 1 // Escape Sequence in C #include<stdio.h> #include<conio.h> // \n \t \’ \” int main() { system(“cls”); printf(“*\n**\n***\n****\n******”); // printf(“———————————————–“); // printf(” \n\t 1. Addition\n\t 2. Subtraction \n \t3.Swaping \n\t 4 Exit”); //...