This page contains a collection examples on basic concepts of C programming like: loops, functions, pointers, structures etc.
Feel free to use the source code on your system.
C program for lowwer case of a string using library functions
Feel free to use the source code on your system.
C program for lowwer case of a string using library functions
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char str1[30]; clrscr(); printf("\nEnter a string:"); scanf("%s",str1); strlwr(str1); printf("\nYou have enter string: %s",str1); getch(); }C program for upper case of a string using library functions
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char str1[30]; clrscr(); printf("\nEnter a string:"); scanf("%s",str1); strupr(str1); printf("\nYou have enter string: %s",str1); getch(); }C program for concatenation of two string using library functions
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char str1[30],str2[30]; clrscr(); printf("\nEnter a string 1:"); scanf("%s",str1); printf("\nEnter a string 2:"); scanf("%s",str2); strcat(str1,str2); printf("\nYou have enter string: %s",str1); getch(); }C program for reversing a string using library functions
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char str1[30]; clrscr(); printf("\nEnter a string:"); scanf("%s",str1); strrev(str1); printf("\nYou have enter string: %s",str1); getch(); }C program for copying a string using library function
#include<stdio.h> #include<string.h> #include<conio.h> void main() { char str1[30],str2[30]; clrscr(); printf("\nEnter a string:"); scanf("%s",str1); strcpy(str2,str1); printf("\nYou have enter string: %s",str2); getch(); }C program for writing Alphabets in C using asterik(*)
#include<stdio.h> #include<conio.h> void main() { int j,i; clrscr(); for(i=1;i<=7;i++) { for(j=1;j<=56;j++) { if(j==1||i==1&&j==2||i==1&&j==3||i==1&&j==4||i==7&&j==4||i==7&&j==2||i==7&&j==3||i==7&&j==4||i==6&&j==4||i==2&&j==4||j==7||j==10||i==1&&j==8||i==1&&j==9||i==7&&j==8||i==7&&j==9||j==13||i==1&&j==14||i==1&&j==15||i==7&&j==14||i==7&&j==15||j==16&&i==2||j==16&&i==3||j==16&&i==4||j==16&&i==5||j==16&&i==6||j==19||i==1&&j==20||i==1&&j==21||i==1&&j==22||i==4&&j==20||i==4&&j==21||i==4&&j==22||i==7&&j==20||i==7&&j==21||i==7&&j==22||i==2&&j==27||i==2&&j==29||i==3&&j==28||j==30||j==26||j==33||j==36||i==1&&j==34||i==1&&j==35||i==7&&j==34||j==45||i==7&&j==35||j==39||i==1&&j==40||i==1&&j==41||i==7&&j==40||i==7&&j==41||j==42&&i==2||j==42&&i==3||j==42&&i==4||j==42&&i==5||j==42&&i==6||j==19||i==1&&j==46||i==1&&j==47||i==1&&j==48||i==4&&j==46||i==4&&j==47||i==4&&j==48||i==7&&j==46||i==7&&j==47||i==7&&j==48||j==55||i==1&&j==52||i==1&&j==53||i==1&&j==54||i==2&&j==52||i==4&&j==54||i==4&&j==56) { printf("*"); } else { printf(" "); } } printf("\n"); } getch(); }C Program for sum of columns of the matrix
#include<stdio.h> #include<conio.h> void main() { int i,j,a[3][3],sum1=0,sum2=0,sum3=0; clrscr(); printf("\nEnter the matrix"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("\nYou have entered matrix:\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\t%d",a[i][j]); } printf("\n"); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(j==0) sum1=a[i][j]+sum1; else if(j==1) sum2=a[i][j]+sum2; else if(j==2) sum3=a[i][j]+sum3; } } printf("\nSum1=%d\nSum2=%d\nSum3=%d",sum1,sum2,sum3); getch(); }C program for displaying UNIT matrix.
#include<stdio.h> #include<conio.h> void main() { int i,j,a[3][3]; clrscr(); printf("\nEnter the matrix:\n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(i==j) { a[i][j]=1; printf("%d\t",a[i][j]); } else { a[i][j]=0; printf("%d\t",a[i][j]); } } printf("\n"); } getch(); }C program for transposing of matrix.
#include<stdio.h> #include<conio.h> void main() { int i,j,a[3][3]; clrscr(); printf("\nEnter the matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } printf("\n"); } printf("\n\n"); printf("\natfer transpose\n"); for(j=0;j<3;j++) { for(i=0;i<3;i++) { printf("%d\t",a[i][j]); } printf("\n"); } getch(); }C program for addition of two matrix
void main() { int i,j,a[3][3],b[3][3],add[3][3]; clrscr(); printf("\nEnter the matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } printf("\n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } printf("\n"); } printf("\n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",b[i][j]); } printf("\n"); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { add[i][j]=a[i][j]+b[i][j]; } } printf("\n\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",add[i][j]); } printf("\n"); } getch(); }C program for displaying matrix
#include<stdio.h> #include<conio.h> void main() { int i,j,a[3][3]; clrscr(); printf("\nEnter the matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } printf("\n"); } getch(); }C program for sorting (BUBBLE SORT)
#include<stdio.h> #include<conio.h> void main() { int i,j,temp,a[10]; clrscr(); printf("\nEnter the numbers: "); for(i=0;i<10;i++) scanf("%d",&a[i]); printf("\nBefore sorting- "); for(i=0;i<10;i++) printf("\t%d",a[i]); for(i=0;i<10;i++) { for(j=i+1;j<10;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } printf("\nAfter sorting: "); for(i=0;i<10;i++) printf("\t%d",a[i]); getch(); }C program for finding sum of n numbers.
//find sum of n no #include<stdio.h> #include<conio.h> void main() { int sum=0,n,i; printf("\nEnter n number"); scanf("%d",&n); for(i=0;i<n;i++) sum=sum+i; printf("Sum of n number - %d",sum); getch(); }C program for sum of 10 numbers.
#include<stdio.h> #include<conio.h> void main() { int sum=0,i; clrscr(); for(i=0;i<10;i++) sum=sum+i; printf("sum of ten no- %d",sum); getch(); }C program for displaying 100 even numbers.
#include<stdio.h> #include<coonio.h> void main() { int num=0,i; clrscr(); for(i=0;i<=100;i++) { if(num%2==0) { printf("\t%d",num); } num++; } getch(); }C program for displaying day
// C program displaying day #include<stdio.h> #include<conio.h> void main() { int a; clrscr(); printf("Enter a number between 1-7 for displaying day!!!-"); scanf("%d",&a); if(a==1) printf("\nThe day is monday!!!"); else if(a==2) printf("\nThe day is tuesday!!!"); else if(a==3) printf("\nThe day is wednesday!!!"); else if(a==4) printf("\nThe day is thursday!!!"); else if(a==5) printf("\nThe day is friday!!!"); else if(a==6) printf("\nThe day is saturday!!!"); else if(a==7) printf("\nThe day is sunday!!!"); getch(); }C program for find greater number
//To find Greater number #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("\nEnter three numbers- "); scanf("%d%d%d",&a,&b,&c); if(a>b && a>c) printf("\n%d is greater number!!!",a); else if(b>a && b>c) printf("\n%d is greater number!!!",b); else printf("\n%d is greater number!!!",c); getch(); }C program for find vowel or consonant
//to find vowel our consonant #include<stdio.h> #include<conio.h> void main() { char ch; clrscr(); printf("\nEnter a Alphabet- "); scanf("%c",&ch); if(ch=='a'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u') printf("\nYou have entered a vowel!!!"); else if(ch=='A'|| ch=='E'|| ch=='I'|| ch=='O'|| ch=='U') printf("\nYou have entered a vowel!!!"); else printf("\nYou have entered a consonant!!!"); getch(); }C program for sum of first and last digit of four digit number
//Addition of four digit numbe #include<stdio.h> #include<conio.h> void main() { int sum=0,rem,num; clrscr(); printf("\nEnter a four digit number- "); scanf("%d",&num); rem=num%10; sum=sum+rem; num=num/10; rem=num%10; sum=sum+rem; num=num/10; rem=num%10; sum=sum+rem; num=num/10; rem=num%10; sum=sum+rem; num=num/10; printf("\nAddition of four digit number- %d",sum); getch(); }C program to reverse a four digit number
void main() { int num,rev=0,rem; clrscr(); printf("\nEnter a four digit number- "); scanf("%d",&num); rem=num%10; rev=rev*10+rem; num=num/10; rem=num%10; rev=rev*10+rem; num=num/10; rem=num%10; rev=rev*10+rem; num=num/10; rem=num%10; rev=rev*10+rem; num=num/10; printf("\nThe reversed number- %d",rev); getch(); }C program for finding area of triangle
//C program to find area of triangle #include<stdio.h> #include<conio.h> #define half 0.5 void main() { int length,breadth; float area; clrscr(); printf("\nEnter the Length- "); scanf("%d",&length); printf("\nEnter the Breadth- "); scanf("%d",&breadth); area=half*length*breadth; printf("\nArea of triangle- %.3f",area); getch(); }C Program for swaping two numbers without using third vaariable
//swaping two number without using third variable #include<stdio.h> #include<conio.h> void main() { int a,b,temp; clrscr(); printf("\nEnter value of A- "); scanf("%d",&a); printf("\nEnter value of B- "); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\nAter Swap- "); printf("A=%d\t\tB=%d",a,b); getch(); }C Program for find Area
void main() { int r; float area; clrscr(); printf("\nEnter a number to find the Area- "); scanf("%d",&r); area=pie*r*r; printf("\nArea= %.2f",area); getch(); }C Program for swaping two variable using third variable
#include<stdio.h> #include<conio.h> void main() { int a,b,temp; temp=0; clrscr(); printf("\nEnter number A: "); scanf("%d",&a); printf("\nEnter number B: "); scanf("%d",&b); temp=a; a=b; b=temp; printf("\nAfter SWAP:"); printf("A=%d\t\tB=%d",a,b); getch(); }C Program for displaying discount
#include<stdio.h> #include<conio.h> void main() { int price,amt,no,disc=0; clrscr(); printf("Enter the amount you have purchased- "); scanf("%d",&amt); printf("Enter the no: "); scanf("%d",&no); price=amt*no; if(price>2000) { disc=price-price*40/100; printf("\nYou have got discount of rupees-%d ",disc); } else if(price<1000) { disc=price-price*30/100; printf("\nYou have got discount of rupees-%d ",disc); } getch(); }C Program for printing a number n time
#include<stdio.h> #include<conio.h> void main() { int num,i=1; clrscr(); printf("Enter a number-"); scanf("%d",&num); while(i<=num) { printf("\n%d",num); i++; } getch(); }C program for displaying 1 - 10 table.
//display 1-10 table #include<stdio.h> #include<conio.h> void main() { int num=1,i,j; clrscr(); for(i=1;i<11;i++) { for(j=1;j<=10;j++) printf("\n%d X %d = %d",num,j,num*j); printf("\t"); num++; } getch(); }C program for displaying pattern
//c program for displaying pattern #include<stdio.h> #include<conio.h> void main() { int j,i; clrscr(); for(i=0;i<=4;i++) { for(j=0;j<=4;j++) { if(i==0||i==4||j==0||j==4||i==2&&j==2) { printf("*"); } else printf(" "); } printf("\n"); } getch(); }C program for displaying elements in array
//C program for displaying elements in array #include<stdio.h> #include<conio.h> void main() { int j,i; clrscr(); printf("Enter the array- "); for(i=0;i<10;i++) scanf("%d",&a[i]); printf("\nThe array element -\n "); for(i=0;i<10;i++) printf("%d\t",a[i]); getch(); }C program for finding out the leap year
//to find out the leap year #include<stdio.h> #include<conio.h> void main() { int year; clrscr(); printf("\nEnter a year- "); scanf("%d",&year); if(year%4==0 && year%100==0 || year%400==0) printf("\nThe year you have enter is leap year!!!"); else if(year%4!=0 && year%100!=0 || year%400!=0) printf("\nThe year you have enter is not leap year!!!"); getch(); }C program for addition of four digit number
//Addition of four digit number #include<stdio.h> #include<conio.h> void main() { int sum=0,rem,num; clrscr(); printf("\nEnter a four digit number- "); scanf("%d",&num); rem=num%10; sum=sum+rem; num=num/10; rem=num%10; sum=sum+rem; num=num/10; rem=num%10; sum=sum+rem; num=num/10; rem=num%10; sum=sum+rem; num=num/10; printf("\nAddition of four digit number- %d",sum); getch(); }
Comments
Post a Comment