EmbLogic's Blog

Author Archives: Amardeep Rawat

c program to print string and find its leght without using

#include int main() { char p[]=”amardeep singh rawat”; int i=0; int count=0; printf(“String elemen are:\n”); while(p[i]!=”) { printf(“%c\n”,p[i]); i++; count++; } printf(“string is:%s\n”,p); printf(“Length of string is:%d\n”,count); return 0; }

Posted in Data Structures with C | Leave a comment

C program to insert an element in an array of size 10

#include int main() { int n,i,a[10]={1,2,3}; printf(“enter element you want to add:”); scanf(“%d”,&n); for(i=9;i>=0;i–) { a[i]=a[i-1]; if(i==0) a[i]=n; // printf(“a[%d]=%d\n”,i,a[i]); } printf(“After adding element:\n”); for(i=0;i<9;i++) { printf("a[%d]=%d\n",i,a[i]); } }

Posted in Data Structures with C | Leave a comment

C program for bubble sorting

#include int main() { int i,j,k,a[100],n; printf(“Enter size of array:”); scanf(“%d”,&n); printf(“Enter element of an array:”); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { for(j=0;ja[j+1]) { k=a[j]; a[j]=a[j+1]; a[j+1]=k; } } } printf(“Array after bubble sorting:\n”); for(i=0;i<n;i++) { printf("a[%d]=%d\n",i,a[i]); } }

Posted in Data Structures with C | Leave a comment

C program to compute area of triangle and square

#include int main() { int area,triangle,side,base,height; char ch; printf(“Enter s for area and t for triangle:”); scanf(“%c”,&ch); switch(ch) { case ‘s’: printf(“Enter side:”); scanf(“%d”,&side); area=side*side; printf(“Area of square = %dm^2\n”,area); break; case ‘t’: printf(“Enter base and hight:”); scanf(“%d%d”,&base,&height); area=(base*height)/2; printf(“Area … Continue reading

Posted in Data Structures with C | Leave a comment

Write a c program to add two array of size 10 and store the sum into third array

#include int main() { int i,a[10],b[10],c[10]; printf(“Enter the element of array1:\n”); for(i=0;i<10;i++) { scanf("%d",&a[i]); } printf("Enter the element of array2:\n"); for(i=0;i<10;i++) { scanf("%d",&b[i]); } printf("Element of array3 are:\n"); for(i=0;i<10;i++) { c[i]= a[i]+b[i]; printf("a[%d]+b[%d]=%d\n",i,i,c[i]); } }

Posted in Data Structures with C | Leave a comment

C program for digital clock

#include int main() { int sec=0,min=0,hour=0,i,j; while(1) { if(sec>59) { min++; sec=0; } if(min>59) { hour++; min=0; } if(hour>23) { hour=0; min=0; sec=0; } sleep(1); sec=sec+1; system(“clear”); printf(“\t\t%d:%d:%d\n”,hour,min,sec); } }

Posted in Data Structures with C | Leave a comment

C program for sorting an array in asscending order and binary searching

#include int main() { int i,j,a[100],b,n,c,low,mid,high; printf(“How many no. you want to add in an array:”); scanf(“%d”,&n); printf(“Enter element of array:\n”); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { for(j=i+1;ja[j]) { b=a[i]; a[i]=a[j]; a[j]=b; } } } printf(“Array after sorting is:\n”); for(i=0;ia[mid]) … Continue reading

Posted in Data Structures with C | Leave a comment

C program to merge two aaray

#include int main() { int a[100],b[100],i,j,k,l,c[100],m,n,o,x,y; printf(“How many no. do you want to add in array a[100]:”); scanf(“%d”,&n); printf(“Enter element of first array:\n”); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("How many no. do you want to add in array b[100]:"); scanf("%d",&o); printf("Enter … Continue reading

Posted in Data Structures with C | Leave a comment

C program for sorting an array in asscending order

#include<stdio.h> int main() { int a[100],i,j,n,temp; printf(“How many no. you want to add in an array:”); scanf(“%d”,&n); printf(“Enter element of an array:\n”); for(i=0;i<n;i++) { scanf(“%d”,&a[i]); } printf(“Array before sorting is:\n”); for(i=0;i<n;i++) { printf(“%d\n”,a[i]); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { … Continue reading

Posted in Data Structures with C | Leave a comment