Posts

create personal blog

Image
How to create personal blog

write a program to de-allocate the memory then free the allocated memory.

Image
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int n,i; int *ptr; printf("enter the no. of elements:"); scanf("%d",&n); ptr=(int*)malloc(n*sizeof(int)); printf("memory allocated using malloc\n"); for(i=0;i<n;i++) { ptr[i]=i+1; } free(ptr); printf("\nmemory freed"); return 0; }

write a program to reallocate the memory dynamically using re-alloc method .

Image
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int n,i; int *ptr; printf("enter the no. of elements:"); scanf("%d",&n); ptr=(int*)calloc(n,sizeof(int)); printf("memory allocated using calloc\n"); for(i=0;i<n;i++) { ptr[i]=i+1; } printf("elements in the array are\n"); for(i=0;i<n;i++) { printf("%d\n",ptr[i]); } printf("enter the new size:"); scanf("%d",&n); ptr=realloc(ptr,n*sizeof(int)); printf("memory reallocated using realloc\n"); for(i=0;i<n;i++) { ptr[i]=i+1; } printf("elements of array are\n"); for(i=0;i<n;i++) { printf("%d\n",ptr[i]); } return 0; }

write a program to allocate the memory dynamically using malloc.

Image
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int i,n; int *ptr; printf("enter the no. of elements\n"); scanf("%d",&n); ptr=(int*)malloc(n*sizeof(int)); printf("memory allocated\n"); for(i=0;i<n;i++) { ptr[i]=i+1; } printf("elements in the array are\n"); for(i=0;i<n;i++) { printf("%d\n",ptr[i]); } return 0; }

write a program to find whether the sum of the triplet is equal to the given value.

Image
#include<stdio.h> #include<conio.h> int main() { int a[5]={4,2,3,8,12}; int i,j,k,sum=15,p=0; for(i=0;i<5;i++) { for(j=i+1;j<5;j++) { for(k=j+1;k<5;k++) { if(a[i]+a[j]+a[k]==sum) { p=1; } } } } printf("%d",p); return 0; } #include<stdio.h> #include<conio.h> int main() { int a[5]={4,2,3,8,12}; int i,j,k,sum=25,p=0; for(i=0;i<5;i++) { for(j=i+1;j<5;j++) { for(k=j+1;k<5;k++) { if(a[i]+a[j]+a[k]==sum) { p=1; } } } } printf("%d",p); return 0; }

wwrite a program to enter number of digits and form a number using these digits.

Image
#include<stdio.h> #include<math.h> int main() { int n,i,a[10],s=0; printf("enter the no of digit "); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter the %d th digit ",i); scanf("%d",&a[i]); } i=0; while(i<n) { s=s+a[i]*pow(10,i); i++; } printf("the no is %d",s); return 0; }  

write a program to concatenate two string without using stract().

Image
#include<stdio.h> #include<conio.h> int main() { char str1[50],str2[50],i,j; printf("enter first string\n"); scanf("%s",&str1); printf("enter second string\n"); scanf("%s",&str2); for(i=0;str1[i]!='\0';i++); for(j=0;str2[j]!='\0';j++,i++) { str1[i]=str2[j]; } str1[i]='\0'; printf("\n output is %s",str1); return 0; }  

write a program to find

Image
#include<stdio.h> #include<conio.h> int main() { int a; printf("enter no between 1 to 5:"); scanf("%d",&a); switch(a) { case 1: { printf("hello"); } break; case 2: { printf("abhishek"); } break; case 3: { printf("bro"); } break; case 4: { printf("how are you"); } break; default: printf("error found⚠️⚠️"); } return 0; }

write a program to find whether a character is vowel or not by using switch case .

Image
#include<stdio.h> #include<conio.h> int main() { char ch; printf("enter a character:"); scanf("%c",&ch); switch(ch) { case 'a': case 'e': case 'i': case 'o': case 'u': printf("%c is  vowel",ch); break; default: printf("%c is not vowel",ch); break; } return 0; }

write a program to create a calculator using switch case.

Image
#include<stdio.h> #include<conio.h> int main() { int a,b; char operator; printf("enter operator(+,-,*,/):"); scanf("%c",&operator); printf("enter two number"); scanf("%d%d",&a,&b); switch(operator) { case '+': printf("%d",a+b); break; case '-': printf("%d",a-b); break; case '*': printf("%d",a*b); break; case '/': printf("%d",a/b); break; default: printf("error danger⚠️⚠️⚠️ 😭😭"); break; } return 0; }

write a program to print pattern(pyramid) for inverted half pyramid.

Image
#include<stdio.h> #include<conio.h> int main() { int i,j,n; printf("enter the number "); scanf("%d",&n); for(i=n;i>=1;i--) { for(j=1;j<=i;j++) { printf("🔥"); } printf("\n"); } return 0; }

write a program to print half pyramid(pattern).

Image
#include<stdio.h> #include<conio.h> int main() { int i,j,n; printf("enter the number "); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf("🔥"); } printf("\n"); } return 0; }

write a program for insertion sort with example .

Image
#include<stdio.h> #include<conio.h> int main() { int a[50],n,i,j,temp; printf("enter size of an array\n"); scanf("%d",&n); printf("\nenter element in array\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=1;i<n;i++) { temp=a[i]; j=i-1; while(j>=0 && a[j]>temp) { a[j+1]=a[j]; j=j-1; } a[j+1]=temp; } for(i=0;i<n;i++) { printf("\t%d\n",a[i]); } return 0; }

write a program for bubble sort with example .

write a program to print prime number between 1 to 50.

Image
#include<stdio.h> #include<conio.h> int main() { int i,j,ans; printf("Prime Number between 1 to 50\n"); for(j=1;j<=50;j++) { ans=0; for(i=2;i<=j/2; i++) { if(j%i==0) { ans++; } } if(ans==0&&j!=1) { printf("%d\n",j); } } return 0; }

write a program to find the product or multiplication of two matrices.

Image
#include<stdio.h> #include<conio.h> int main() { int a[3][3],b[3][3],c[3][3],sum=0,i,j,k; printf("enter value of first matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) scanf("%d",&a[i][j]); } printf("enter value of second matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) scanf("%d",&b[i][j]); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { sum=0; for(k=0;k<3;k++) sum=sum+a[i][k]*b[k][j]; c[i][j]=sum; } } printf("multiplication of two matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t",c[i][j]); printf("\n"); } return 0; }

write a program to store the information of student by using union.

Image
#include<stdio.h> #include<conio.h> union student { char name[10]; int rollno; }; main() { union student stu; printf("enter student name\n"); scanf("%s",&stu.name); printf("student name is %s\n",stu.name); printf("enter student rollno\n"); scanf("%d",&stu.rollno); printf("student rollno is %d\n",stu.rollno); return 0; }

Function with argument but no return value. Write a program to find the addition of two number using function with argument but no return value

Image

write a program to find sum of two numbers by using function with no argument no return value. write a program of the following operations. a)input 2 number from the user. Add and display the result b)repeat step(a) c)print your name d)product e)product

write a program to find the sum of two numbers 3 times using no argument and no return value.

Image