Posts

Showing posts with the label c languge

Practice examples on c language for beginners

Image
Solve these questions by your own:  Q.1. Who designed and written C language? (a)                                           (b) Dennis Ritchie (c)                                            (d) Q.2. In C language array fall under which category of constants? (a) Primary                          (b) Secondary Q.3. Which of the following int variable eligible to stored? (a) 264         ...

Perform a task with calloc statement | C -Program

Image
calloc(  ,  ) statement: Code: #include<stdio.h> #include<stdlib.h> void main() { int *p,n,i; printf("Enter the size of array:\n"); scanf("%d",&n); p=calloc(n,2); printf("Enter the array elements:\n"); for(i=0;i<n;i++) scanf("%d",p+i); printf("Elements are:\n"); for(i=0;i<n;i++) printf("%d\t",*(p+i)); } Output:

Compound Interest in c language

Image
C Program To Calculate Compound Interest You need to know : Arithmetic operators. Data type. BODMAS rule.                // To know precedence of an operator. Basic input and output system. Formula Of Compound Interest : Compound Interest = Principle * (1 + Rate / 100 )^T or ci  =  p * pow ( ( 1 + r / 100 ) , t ) Wondering what is pow!!   We got it covered, click here . Tips To Do The Program : Take input of principle amount from user. store in a variable like principle. Do same from Time and Rate. Store it in some appropriate variables like time and rate. Now calculate the Compound Interest using the above formula and store it in a variable say ci. Lastly, show the value of ci to the user. Don't forget to optimize the program for a good look and output. Code : #include<stdio.h> #include<math.h> void main() {       ...

Print Fibonacci Series using Recursion | C program :

Image
Write a C Program to Print Fibonacci series user given range using recursion , C program : Code: #include<conio.h> #include<stdio.h> void main() { int fibo(int); int n,i; printf("Enter the range of fibo:\n"); scanf("%d",&n); for(i=0;i<=n;i++) printf("%d\t",fibo(i)); getch(); } int fibo(int i) { if(i==0 || i==1) return 1; else return (fibo(i-1)+ fibo(i-2)); } Output:

Palindrome number | C language

Image
About Palindrome: Write a C-Program to check weather the number is palindrome or not: Code: #include<stdio.h> #include<conio.h> void main() { int n,m,a,b=0; printf("Enter a number:\n"); scanf("%d",&m); n=m; while(n!=0) { a=n%10; n=n/10; b=b*10+a; } printf("%d\n",b); if(b==m) printf("The number is palindrome"); else printf("Not a palindrome"); getch(); } Output:   ------------------- C Program : String Palindrome

Swapping two variable without using third variable | C-Program

Image
Swapping without using third variable: Code: #include<stdio.h> void main() { int a,b; printf("Enter two number:\n"); scanf("%d%d",&a,&b); printf("You decide a= %d and b= %d to swap:\n",a,b); a=a+b; b=a-b; a=a-b; printf("a=%d and b=%d",a,b); } Output:

Print user define multiplication of two matrix | C-program

Image
 Multiplication of matrix: Code: #include<stdio.h> void main() { int a[10][10],b[10][10],c[10][10],i,j,k,n,m,p,q,sum; printf("Enter the size of lst matrix [10][10]:\n"); scanf("%d%d",&m,&n); printf("Enter the elements of 2nd matrix [10][10]:\n"); scanf("%d%d",&p,&q); if(n==p) { printf("Matrix is possible!\n"); printf("Enter elements of 1st matrix:\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) scanf("%d",&a[i][j]); } printf("Enter elements of 2nd matrix:\n"); for(i=0;i<p;i++) { for(j=0;j<q;j++) scanf("%d",&b[i][j]); } for(i=0;i<m;i++) { for(j=0;j<q;j++) { sum=0; for(k=0;k<n;k++) ...

Perform a task with realloc statement | C - Program

Image
realloc( ) statement:   Code: #include<stdio.h> #include<stdlib.h> void main() { int n,*p,i,*q; printf("Enter the size of elements:\n"); scanf("%d",&n); p=(int*)malloc(n); printf("Enter the elements:\n"); for(i=0;i<n;i++) scanf("%d",p+i); printf("The elements are:\n"); for(i=0;i<n;i++) printf("%d\t",*(p+i)); printf("\nEnter the new size:\n"); scanf("%d",&n); q=realloc(p,n); printf("Enter the new elements:\n"); for(i=0;i<n;i++) scanf("%d",q+i); for(i=0;i<n;i++) printf("%d\t",*(q+i)); } Output:  Comment for your feedback!

Perform a task with malloc statement | C-Program

Image
malloc() statement: Code: #include<stdio.h> #include<stdlib.h> #include<stdio.h> #include<stdlib.h> void main() { int n,*p,i; printf("Enter the size of elements:\n"); scanf("%d",&n); p=(int*)malloc(n); printf("Enter the elements:\n"); for(i=0;i<n;i++) scanf("%d",p+i); printf("The elements are:\n"); for(i=0;i<n;i++) printf("%d\t",*(p+i)); } Output: Comment for your feedback!

Armstrong Number | C-Program

Image
About Armstrong number:   1. Write a C-program to print Armstrong number up to 1000: Code: #include<stdio.h> void main() { int i,j,k,s; printf("The amstrong number are:\n"); for(i=1;i<=1000;i++) { j=i; s=0; while(j!=0) { k=j%10; s=s+k*k*k; j=j/10; } if(s==i) printf("%d\n",i); } } Output:

Print fibonacci series | C-program

Image
Fibonacci series: Tips: You should know Fibonacci series concept. Use for loop. Do swapping. Code : #include<stdio.h> void main() { int i,a=-1,b=1,c; for(i=1;i<=9;i++) { c=a+b; printf("%d\t",c); a=b; b=c; } getch(); } Output: Comment for your feedback!

Sorting array elements with bubble sort | Without Using Function | Using Function | Pointer | C-program

Image
Bubble Sort: Tips:  Use for loop. Use if and else. Do swapping. Bubble sort is done from starting of array.   Without Function: Code: #include<stdio.h> void main() { int i,j,k,a[]={9,2,7,3}; for(j=0;j<=3;j++) for(i=0;i<3;i++) { if(a[i]>a[i+1]) { k=a[i]; a[i]=a[i+1]; a[i+1]=k; } } for(i=0;i<=3;i++) { printf("%d\t",a[i]); } getch(); } Using function Code: #include<stdio.h> void main() { int i,a[]={9,6,7,3},n; sort(a,3); for(i=0;i<=3;i++) { printf("%d\t",a[i]); } getch(); } void sort(int a[],int n) { int i,j,k; for(j=0;j<=n;j++) for(i=0;i<=n;i++) { if(a[i]>a[i+1]) { k=a[i]; a[i]=a[i+1]; a[i+1]=k; ...