Posts

Showing posts with the label c programming

Program for accepting values in array and sort them in ascending order.

Program for accepting values in array and sort them in ascending order. /*Program for accepting values in array and sort them in ascending order.*/ #include<stdio.h> #include<conio.h> void main() { int a[5],i,j,t; clrscr(); printf("\nEnter 5 values in array: "); for(i=0;i<=4;i++) { scanf("%d",&a[i]); } printf("\nBefore arranging array values are:"); for(i=0;i<=4;i++) { printf("%d\t",a[i]); } for(i=0;i<=4;i++) { for(j=i+1;j<=4;j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } } printf("\nAfter arranging in accending order array values are: \n"); for(i=0;i<=4;i++) printf("%d\t",a[i]) ; getch(); }

Program for accepting values in an array and finding greatest and smallest value in that array.

Program for accepting values in an array and finding greatest and smallest value in that array. /*Program for finding greatest and smallest value in an array.*/ #include<stdio.h> #include<conio.h> void main() { int a[5],i,g,s; clrscr(); printf("\nEnter 5 values in array: \n"); for(i=0;i<=4;i++) { scanf("\n%d",&a[i]); } g=s=a[0]; printf("\n Accepted array values are:"); for(i=0;i<=4;i++) { if(g<a[i]) g=a[i]; if(s>a[i]) s=a[i]; printf("%d\t",a[i]); } printf("\n Greatest value is=%d",g); printf("\n\n Smallest value is=%d",s); getch(); }

A Program for accepting values to 2-Dimensional array and finding the sum of all the elements of 2-Dimensional array.

A Program for accepting values to 2-Dimensional array and finding the sum of all the elements of 2-Dimensional array. Just copy and paste the code below and compile and run the program. #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j,s=0; clrscr(); for(i=0;i<3;i++) { for(j=0;j<3;j++)     {       printf("\nEnter a value:");       scanf("%d",&a[i][j]);     }   } printf("\nYour array\n"); for(i=0;i<3;i++) {   for(j=0;j<3;j++)   {   s=s+a[i][j];   printf("%d\t",a[i][j]);   } } printf("\nSum of array elements=%d",s); getch(); }

Change the output's text colour in C

Hi friends, today I am going to share a funny code with you, which will change the colour of the text of out of your C console proram.  here's the code is. : #include<stdio.h> #include<conio.h> int main() {    clrscr();    textcolor(8);    cprintf("Hello world");    getch();    return 0; } You can change the value of  "textcolor(n);" function.  here "n" may be any interger value. Try it and have fun..

Sum up to given number.

A program for find the sum upto the number entered by the user: #include<stdio.h> #include<conio.h> void main() { clrscr(); int y,t,sum=0; printf("Enter the last value of the series, up to where the sum is required:  "); scanf("%d",&t); for(y=1;y<=t;y++) {  sum=sum+y; } printf("Sum of the series is: %f",sum); getch(); getch(); }

Program to find "Factorial value".

Program code for factorial without recursion : #include<stdio.h> #include<conio.h> void main()     { int i,f=1,n; clrscr(); printf("\nEnter a value: \n"); scanf("%d",&n); for(i=1;i<=n;i++)   { f=f*i;   } printf("Factorial value = %d",f); getch();     }

Pattern Printing

Image
Hi friends.. After a long time i am here back with program codes now. today i am going to write a program for pattern printing. I am writing code to print the following pattern: Code to print this pattern is:  #include<stdio.h> #include<conio.h> void main() { int i,j,k; clrscr(); i=1; while(i<=13) { if(i<=4) { k=3;    while(k>=i)     {       printf(" ");       k--;     }      j=1;      while(j<=i)      {       printf("* ");       j++;      }  }  if(i>4 && i<=7)  {   k=5;   while(k<=i)   {   printf(" ");   k++;   }   j=7;   while(j>=i)   {   printf("* ");   j--;   }   }   if(i>7 && i<=10)   {...