Skip to main content

Posts

Showing posts from January, 2014

C program for finding the largest number in an array

#include<stdio.h> #include<conio.h> void main() { int *arr, i, j, n, LARGE; clrscr(); printf(“Enter the number of elements in the array”); scanf(“%d”, &n); arr=(int*) malloc(sizeof(int)*n); for(i=0; i<n; i++) { printf(“Enter a number”); scanf(“%d”, &arr[i]); } LARGE=arr[0]; for(i=1; i<n;i++) { if(arr[i]>LARGE) LARGE=arr[i]; } printf(“The largest number in the array is : %d”, LARGE); getch(); }

C program for sorting the elements of an array in descending order.

#include<stdio.h> #include<conio.h> void main() { int *arr, temp, i, j, n; clrscr(); printf(“enter the number of elements in the array”); scanf(“%d”, &n); arr=(int*)malloc(sizeof(int)*n); for(i=0;i<n;i++) { for(j=i+1; j<n; j++) { if(arr[i]<arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } printf(“Elements of array in descending order are”); for(i=0; i<n; i++); getch(); }

C program to find number of Occurrences of Vowels, Consonants, Words, Spaces and Special Characters in the Given Statement.

#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> #include<ctype.h> void main() { char s[100]; int vow=0,cons=0,spc=0,punc=0,l,i; clrscr(); printf(“enter the statement\n”); gets(s); l=strlen(s); for(i=0;i<l;i++) { if(isalpha(s[i])) { if(s[i]==’a’||s[i]==’e’||s[i]==’i’||s[i]==’o’||s[i]==’u’) { vow++; } else { cons++; } } if(isspace(s[i]) { spc++; } if(ispunct(s[i])) { punc++; } } printf(“\nno.of words=%d”,spc+1); printf(“\nno.of vowels=%d”,vow); printf(“\nno.of consonants=%d”,cons); printf(“\nno.of space=%d”,spc); printf(“\nno.on special characters=%d”,punc); getch(); } Also Read :  1)  Principles of Server Virtualization https://codingpush.blogspot.com/2021/01/principles-of-server-virtualization.html  2) Top Ten Data Storage Tools https://codingpush.blogspot.com/2021/01/top-ten-data-storage-tools.html 3) Implement a simple calculator (detailed comments on ...

C Program to find square of a number using functions.

#include<stdio.h> #include<conio.h> void main() { int rev(int); int r,a; clrscr(); printf(“enter any no: ”); scanf(“%d”,&a); r=rev(a); printf(“square is : %d”,r); getch(); } int rev(int x) { return(x*x); } Also Read :  1)  Principles of Server Virtualization https://codingpush.blogspot.com/2021/01/principles-of-server-virtualization.html  2) Top Ten Data Storage Tools https://codingpush.blogspot.com/2021/01/top-ten-data-storage-tools.html 3) Implement a simple calculator (detailed comments on JAVA code) https://codingpush.blogspot.com/2021/01/implement-simple-calculator-detailed.html 4) What is a Livelock scenario in java? https://codingpush.blogspot.com/2020/12/what-is-livelock-scenario-in-java.html 5) What is Disk scheduling algorithm in java ( code Example)  https://codingpush.blogspot.com/2021/01/disk-scheduling-algorithm-java-code.html 6) What is a Deadlock situation in Java? What are the minimum ...

C Program to find subtraction of two matrices.

#include<stdio.h> #include<conio.h> void main() { int a[5],b[5],c[5],i; clrscr(); printf(“enter value for array a ”); for(i=0;i<5;i++) scanf(“%d”,&a[i]); printf(“enter value for array b ”); for(i=0;i<5;i++) scanf(“%d”,&b[i]); for(i=0;i<5;i++) c[i]=a[i]-b[i]; printf(“subtraction”); for(i=0;i<5;i++) printf(“ %d ”,c[i]); getch(); } Output: enter value for array a: 7 8 9 4 5 enter value for array b: 4 5 6 1 2 subtraction 3 3 3 3 3

C Program to find sum of two matrices

#include<stdio.h> #include<conio.h> void main() { int a[3][2],b[3][2],c[3][2],i,j; clrscr(); printf(“Enter value for 1 matrix: ”); for(i=0;i<3;i++) { for(j=0;j<2;j++) scanf(“%d”,&a[i][j]); } printf(“Enter value for 2 matrix: ”); for(i=0;i<3;i++) { for(j=0;j<2;j++) scanf(“%d”,&b[i][j]); } for(i=0;i<3;i++) { for(j=0;j<2;j++) c[i][j]=a[i][j]+b[i][j]; } printf(“Sum of matrix is\n”); for(i=0;i<3;i++) { for(j=0;j<2;j++) { printf(“%d\t”,c[i][j]); } printf(“\n”); } getch(); } Output: Enter value for 1 matrix: 1 2 3 4 5 6 Enter value for 2 matrix: 4 5 6 1 3 2 Sum of matrix is 5 7 9 5 8 8