Get Update on recent Technology & Programming

Showing posts with label C Programs. Show all posts
Showing posts with label C Programs. Show all posts

Wednesday, 15 November 2017

C Program to convert a binary number to a decimal number

C Program to convert a binary number to a decimal number #include<stdio.h> int main(void) { int n,nsave,rem,d,j=1,dec=0; printf("Enter the number in binary : "); scanf("%d",&n); nsave=n; while(n>0) { rem=n%10; /*taking last digit of n*/ d=rem*j;...

C Program to find the factorial of any number

C Program to find the factorial of any number #include<stdio.h> int main(void) { int n,num; long fact=1; printf("Enter a number : "); scanf("%d",&n); num=n; if(n<0) printf("No factorial of negative number\n"); else { while(n>1) { fact*=n;...

C Program to find the product of digits of any number

C Program to find the product of digits of any number #include<stdio.h> int main(void) { int n,prod=1,rem; printf("Enter a number : "); scanf("%d",&n); while(n>0) { rem = n%10; /*taking last digit of n*/ prod*=rem; n/=10;...

C Program to print the sum of digits of any number

C Program to print the sum of digits of any number #include<stdio.h> int main(void) { int n,sum=0,rem; printf("Enter a number : "); scanf("%d",&n); while(n>0) { rem = n%10; /*taking last digit of n*/ sum+=rem;...

C Program to print numbers in reverse order with a difference of 2

C Program to print numbers in reverse order with a difference of 2 #include<stdio.h> int main(void) { int k=10; while(k>=2) { printf("%d\t",k); k=k-2; } printf("\n"); return 0; } ...

C Program to find whether a year is leap or not

C Program to find whether a year is leap or not #include<stdio.h> int main(void) { int year; printf("Enter year : "); scanf("%d",&year); if(year%100 != 0) { if(year%4 == 0) printf("Leap year\n"); else printf("Not leap\n"); }...

C Program to find biggest number from three given numbers

C Program to find biggest number from three given numbers  #include<stdio.h> int main(void) { int a,b,c,big; printf("Enter three numbers : "); scanf("%d%d%d", &a, &b, &c); if(a>b) { if(a>c) big=a; else big=c; } else { if(b>c)...

C Program to find quotient and remainder

C Program to find quotient and remainder #include<stdio.h> int main(void) { int x,y,quo,rem; printf("Enter two numbers : "); scanf("%d%d",&x,&y); if(y) /*if y is non-zero*/ { quo=x/y; rem=x%y; printf("Quotient=%d, Remainder=%d\n",quo,rem); } else printf("Divide by zero error\n");...

C Program to print a message if negative number is entered

C Program to print a message if negative number is entered #include<stdio.h> int main(void) { int num; printf("Enter a number : "); scanf("%d",&num); if(num<0) { printf("Number entered is negative\n"); num=-num; } printf("Value of num is...

C Program to print whether a number is even or odd

C Program to print whether a number is even or odd #include<stdio.h> int main(void) { int num; printf("Enter a number : "); scanf("%d",&num); if(num%2 == 0) /*test for even */ printf("Number is even\n"); else...

C Program to print the largest Of Two Number

C Program to print the largest Of Two Number #include<stdio.h> int main(void) { int a,b; printf("Enter two numbers : "); scanf("%d%d",&a,&b); if(a>b) printf("Bigger number=%d\n",a); else printf("Bigger number=%d\n",b); return 0; } ...

Tuesday, 14 November 2017

C Program to read records from a file and calculate grade of each student and display it

C Program to read records from a file and calculate grade of each student and display it  grade= A if marks>=80 = B if marks>=60 and < 80 = C if marks<60 #include<stdio.h> #include<stdlib.h> int main(void)...

C Program to Program to append records to a file

C Program to Program to append records to a file #include<stdio.h> #include<stdlib.h> int main(void) { struct record { char name[20]; int roll; int marks; }student; FILE *fp; int choice=1; fp=fopen("stu","ab");/*opened in append mode*/ if(fp==NULL) {...

C Program to Copy a file to another file

C Program to Copy a file to another file #include<stdio.h> #include<stdlib.h> int main(void) { FILE *sptr, *dptr; char ch; if((sptr=fopen("source.txt","r"))==NULL) { printf("Error in opening source file\n"); exit(1); } if((dptr=fopen("destination.txt","w"))==NULL) { printf("Error in opening destination...

Friday, 10 November 2017

C Program to find Prime numbers using sieve Algorithm

C Program to find Prime numbers using sieve Algorithm #include<stdio.h> #define MAX 10000 int main(void) { int p,i,n,a[MAX]={0}; printf("Enter n : "); scanf("%d",&n); p=2; while(p*p <= n) { for(i=2; i*p<=n; i++) /*Cross out all...

C Program of merging two sorted arrays into a third sorted array

C Program of merging two sorted arrays into a third sorted array #include<stdio.h> #define MAX 100 void merge(int arr1[],int arr2[],int arr3[],int n1,int n2); int main(void) { int arr1[MAX],arr2[MAX],arr3[2*MAX],n1,n2,i; printf("Enter the number of elements in...

C Program of sorting using insertion sort

C Program of sorting using insertion sort #include<stdio.h> #define MAX 100 int main(void) { int arr[MAX],i,j,k,n; printf("Enter the number of elements : "); scanf("%d",&n); for(i=0; i<n; i++) { printf("Enter element %d : ",i+1); scanf("%d",...

C Program to insert an item in a sorted array at the proper place by shifting other elements to the right

C Program to insert an item in a sorted array at the proper place by shifting other elements to the right #include<stdio.h> #define SIZE 10 int main(void) { int arr[SIZE]; int i,item; printf("Enter elements...

C Program to insert an item in an array at a specified index by moving other elements to the right

C Program to insert an item in an array at a specified index by moving other elements to the right #include<stdio.h> #define SIZE 10 int main(void) { int arr[SIZE]; int i,item,index; printf("Enter elements of...

Bubble sort In c

#include<stdio.h> #define MAX 100 int main(void) { int arr[MAX],i,j,temp,n,xchanges; printf("Enter the number of elements : "); scanf("%d",&n); for(i=0; i<n; i++) { printf("Enter element %d : ",i+1); scanf("%d",&arr[i]); } /*Bubble sort*/ for(i=0; i<n-1 ;i++) {...

Hey, we've just launched a new custom color Blogger template. You'll like it -
Join Our Newsletter