Showing posts with label Programs Code In C. Show all posts
Showing posts with label Programs Code In C. Show all posts

Monday, 1 February 2016

Print Star Pattern in C

Print Star Pattern in C

Hello friends Today we write code for Print Star Pattern in C or Print Triangle of star in C . For this program you need for loop concept and break line concept.

Code for Star Triangle

#include <stdio.h>
#include <conio.h>
 void main()
{
 int row, c, n, temp;
 printf("Enter the number of rows in pyramid of stars you want to see: ");
 scanf("%d",&n); temp = n;
 for ( row = 1 ; row <= n ; row++ )
 {
 for
 ( c = 1 ; c < temp ; c++ )
 printf(" "); temp--;
 for ( c = 1 ; c <= 2*row - 1 ; c++ )
 printf("*");
 printf("\n");
 }
 getch();
}

Output:

Enter the number of rows in pyramid of stars you want to see: 5
        *
      ***
    *****
  *******
*********

Print Below Pattern

*
**
***
****
*****

Code for Above Pattern


#include <stdio.h>
#include <conio.h>
void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

Friday, 10 January 2014

Swap Two Number

Swap Two Number

Swap two number program is nothing just exchange their values.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
textcolor(RED);
gotoxy(25,18);
cprintf("enter valu of a = ");
scanf("\n%d",&a);
gotoxy(25,20);
textcolor(2);
cprintf("enter valu of b = ");
scanf("\n%d",&b);
a=a+b;
b=a-b;
a=a-b;
gotoxy(25,24);
cprintf("a= %d b= %d",a,b);
getch();
}

Output

Swap Two Number

Change lower case later to upper case

Change lower case later to upper case


#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char ch,c;
clrscr();
textcolor(2);
gotoxy(15,10);
cprintf("enter the any charecter= ");
scanf("%c",&ch);
textcolor(4+5);
gotoxy(15,13);
if(islower(ch))
{
printf("\n");
gotoxy(15,16);
putchar(toupper(ch)); //change in uppercase
}
else
{
gotoxy(15,16);
putchar(tolower(ch));
}
getch();
}

Output

Change lower case later to upper case
 

Thursday, 9 January 2014

C++ program to find sum of digits of a number

C++ program to find the sum of digits of a number

Here we write code for find sum of digits of a number program in C.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,no,sum=0;
clrscr();
printf("enter any num = ");
scanf("%d",&no);
while(no>0)
{
a=no%10;
no=no/10;
sum=sum+a;
}
printf("\nSUM OF DIGITS = %d",sum);
getch();
}

Output

Calculate Sum Of Digits

Count Number Character Symbol From a String

Count Number Character Symbol From a String

C++ Program to Count Character Symbol from String
#include<stdio.h>
#include<conio.h>
int main()
{
char line[150];
int i,v,c,ch,d,s,o;
o=v=c=ch=d=s=0;
clrscr();
printf("Enter a line of string:\n");
gets(line);
for(i=0;line[i]!='\0';++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U')
++v;
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
++c;
else if(line[i]>='0'&&c<='9')
++d;
else if (line[i]==' ')
++s;
}
printf("Vowels: %d",v);
printf("\nConsonants: %d",c);
printf("\nDigits: %d",d);
printf("\nWhite spaces: %d",s);
getch();
}

Output

Count Number Character Symbol From a String

Count Repetition of Character in a string

Count Repetition of Character in a string


#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char ch[10],c;
int count=0;
clrscr();
printf("Enter any string= ");
gets(ch);
printf("Enter any character from string= ");
c=getch();
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]==c)
{
count++;
}
}
printf("\nrepitation of %c = %d times",c,count);
getch();
}

Output

Count Repetition of Character in a string

CHAICK A NUMBER UPPER CASE LOWER CASE

CHAICK A NUMBER UPPER CASE LOWER CASE

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char ch;
clrscr();
textcolor(2);
gotoxy(15,10);
cprintf("enter the any charecter= ");
scanf("%c",&ch);
textcolor(4+5);
gotoxy(15,13);
if(islower(ch))
{
textcolor(12);
gotoxy(15,16);
cprintf("\n lower case small letter");
}
else if(isupper(ch))
{
gotoxy(15,16);
cprintf("upper case capital letter");
}
else if(isdigit(ch))
{
gotoxy(15,16);
cprintf("this no. is digit");
}
else
{
cprintf("this is speciial symbol");
}
getch();
}

Output

CHAICK A NUMBER UPPER CASE LOWER CASE

CHAICK A NUMBER UPPER CASE LOWER CASE

Wednesday, 8 January 2014

Check give number is Armstrong or not

Armstrong program in C

Armstrong number program in C is easy and simple to write, suppose we take any three digits number and check number is armstrong or not; first find cube of all digits and find sum of all digits if sum is equal to number then that number is armstrong number.


#include<stdio.h>
#include<conio.h>
void main()
{
int arm=0,a,b,c,d,no;
clrscr();
printf("Enter any num = ");
scanf("%d",&no);
d=no;
while(no>0)
{
a=no%10;
no=no/10;
arm=arm+a*a*a;
}
if(arm==d)
{
printf("\n%d armstrom",no);
}
else
{
printf("not");
}
getch();
}


Output

Armstrom

Armstrom

Tuesday, 7 January 2014

COPY THE FIRST STRING INTO SECOND STRING

COPY THE FIRST STRING INTO SECOND STRING

Below we write code for copy first string into second string in C

#include<stdio.h>
#include<conio.h>
#include<string.h>
void string(char *ch1 ,char *ch2);
void main()
{
char *ch1[5];
char *ch2="kumar";
clrscr();
printf("\n\nSTRING = %s",ch2);
string(ch1,ch2);
getch();
}
void string(char *ch1 ,char *ch2)
{
strcpy(ch1,ch2);
strupr(ch1);
printf("\n\nSTRING IS = ");
printf("%s",ch1);
}



OUTPUT


COPY THE FIRST STRING INTO SECOND STRING







COMB THE TWO STRING AND PRINT IN UPP CASE

COMB THE TWO STRING AND PRINT IN UPP CASE

In the below program, we combined two string and print in upper case

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *ch1="hitesh ";
char *ch2="kumar";
char *ptr;
clrscr();
printf("\n\n1 ST STRING = %s",ch1);
printf("\n\n2 ND STRING = %s",ch2);
strcat(ch1,ch2);
printf("\n\nSTRING IS = %s",ch1);
ptr=strupr(ch1);
printf("\n\nIN UPPER CASE = ");
printf("%s",ptr);
getch();
}



OUTPUT
COMB THE TWO STRING AND PRINT IN UPP CASE



Sort an array Elements in Ascending Order in C

Sort an array Elements in Ascending Order in C

Sort an array Elements in Ascending Order in C. Array is the collection of similar data type and it store data on the basis of index value. To sort array elements you need to compare first element with next element and second element with third elements and so on.....

#include<stdio. h>
#include<conio. h>
#include<dos. h>
void main()
{
int i,a[10],temp,j;
clrscr();
printf("Enter any 10 num in array = \n");
for(i=0;i<=10;i++)
{
scanf("%d",&a[i]);
}
printf("\n\nData before sorting = ");
for(j=0;j<10;j++)
{
delay(200);
printf(" %d",a[j]);
}
for(i=0;i<=10;i++)
{
for(j=0;j<=10-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("\n\n\nData after sorting = ");
for(j=0;j<10;j++)
{
delay(200);
printf(" %d", a[j]);
}
getch();
}

Output
 
SORT THE ELEMENT OF ARRAY IN ASSENDING ORDER

PASS ARRAY FROM ONE FUNCTION TO ANOTHER

PASS ARRAY FROM ONE FUNCTION TO ANOTHER

#include<stdio.h>
#include<conio.h>
void pass(int[],int);
void main()
{
int a[]={1,2,3,4,5};
clrscr();
pass(a,5);
getch();
}
void pass(int b[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf(" %d\n",b[i]);
}
}


OUTPUT

PASS ARRAY FROM ONE FUNCTION TO ANOTHER



C Program to Reverse a Number

C Program to Reverse a Number

C program to reverse a number is very simple and easy to write. In the below code, i will use some graphics library function to print a message on screen in color.

#include<stdio.h>
#include<conio.h>
void main()
{
int no,rev=0,r,a;
clrscr();
textcolor(10);
cprintf("\n enter the number = ");
scanf("%d",&no);
a=no;
while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;
}
cprintf("\n\n reverse of %d is = %d", a, rev);
getch();
}


Output

C++ Program to Reverse Of A Number

ENTER TWO ARRAY AND MERGE IN 3RD ARRAY

ENTER TWO ARRAY AND MERGE IN 3RD ARRAY

In below code we Enter two array and merge in 3rd array


 #include<stdio.h>
#include<conio.h> 
void merge_array(int a[],int b[]);
void main()
{
int a[10],b[10],i,n;
clrscr();
printf("ENTER ELEMENT IN 1ST ARRAY ");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
printf("ENTER ELEMENT IN 1ST ARRAY ");
for(i=0;i<10;i++)
{
scanf("%d",&b[i]);
}
merge_array(a,b);
getch();
}
void merge_array(int a[],int b[])
{
int c[20],i;
printf("\n\nELEMENT OF 1ST ARRAY");
for(i=0;i<10;i++)
{
printf(" %d",a[i]);
}
printf("\n\nELEMENT of 2ND ARRAY");
for(i=0;i<10;i++)
{
printf(" %d",b[i]);
}
printf("\n\nELEMENT OF ARRAY AFTER MERGE ");
for(i=0;i<10;i++)
{
c[i]=a[i];
}
for(i=0;i<10;i++)
{
c[i+10]=b[i];
}
for(i=0;i<20;i++)
{
printf(" %d",c[i]);
}
}


OUTPUT



ENTER TWO ARRAY AND MERGE IN 3RD ARRAY






Print febonacci series upto 100

Fibonacci series program in C

Fibonacci series program in C; is very simple and easy to write, here i will show you how to write this program. The main concept of this series is add two previous number and get next number.


#include<stdio.h>
#include<conio.h>
void main()
{
double i,twoaway,next,current;
clrscr();
current=0;
next=1;
for(i=1;i<=100;i++)
{
printf(" %lf",current);
twoaway=next+current;
current=next;
next=twoaway;
}
getch();
}

Output

PRINT 100 FIBONOCII SERIES

C Program to Print table of any number

C Program to Print table of any number

C Program to Print table of any number. The general concept to generate table of any number is;number multiply from 1 to 10.

Table Program

#include<stdio.h>
#include<conio.h>
void main()
{
int table(int,int);
int n,i;
clrscr();
printf("Enter any num = ");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf(" %d*%d= %d\n",n,i,table(n,i));
}
getch();
}
int table(n,i)
{
int t;
if(i==1)
{
return(n);
}
else
{
return(table(n,i-1)+n);
}
}

Output



FIND TABLE FO A GIVEN NUM. USING RECURSION

Prime number program in C

Prime number program in C

Prime number program in C. The smallest prime number is 2 and in general prime number is only divisible by 1 and number itself.

Prime Number Program

#include<stdio.h>
#include<conio.h>
void main()
{
int i,no,prime=0;
clrscr();
textcolor(4);
gotoxy(20,10);
cprintf("ENTER ANY NUMBER ");
scanf("%d",&no);
if(no==1)
{
gotoxy(20,12);
printf("%d IS NOT A PRIME NUMBER ",no);
prime=1;
}
for(i=2;i<no;i++)
{
if(no%i==0)
{
gotoxy(20,12);
printf("%d IS NOT A PRIME NUMBER",no);
prime=1;
}
}
if(prime==0)
{
gotoxy(20,12);
printf("%d IS A PRIME NUMBER",no);
}
getch();
} 

Output

CHECK A GIVEN NUMBER IS PRIME OR NOT

Sunday, 5 January 2014

CALCULATE THE BONUS OF EMPLOYEE A/C TO BASIC SALARY

CALCULATE THE BONUS OF EMPLOYEE A/C TO BASIC SALARY


#include<stdio.h>
#include<conio.h>
struct employee
{
char emp_name[20],emp_grad[2];
int emp_bs,emp_code;
float emp_bonus;
};
void main()
{
struct employee emp;
char g;
int hitesh=0;
clrscr();
printf("Enter employee name = ");
gets(emp.emp_name);
printf("Enter employee code = ");
scanf("%d",&emp.emp_code);
printf("Enter Basic salary = ");
scanf("%d",&emp.emp_bs);
printf("Enter Grad of employee = ");
g=getch();
printf("%c",g);
if(g=='a'|| g=='A')
{
emp.emp_bonus=emp.emp_bs*0.5;
printf("\n\nBONUS %f = ",emp.emp_bonus);
hitesh=1;
}
if(g=='b'|| g=='B')
{
emp.emp_bonus=emp.emp_bs*0.1;
printf("\n\nBONUS %f = ",emp.emp_bonus);
hitesh=1;
}
if(g=='c'|| g=='C')
{
emp.emp_bonus=emp.emp_bs*0.02;
printf("\n\nBONUS %f = ",emp.emp_bonus);
hitesh=1;
}
if(hitesh==0)
{
printf("\n\nNo bonus");
}
getch();
}


OUTPUT

CALCULATE THE BONUS OF EMPLOYEE A/C  TO BASIC SALARY


ADDITION OF TWO MATRIX IN C

ADDITION OF TWO MATRIX

Here we write code for Addition of Two Matrix in C

#include<stdio.h>
#include<conio.h>
void main()
{
int x[3][3],y[3][3],z[3][3],i,j;
clrscr();
printf("ENTER ELEMENTS OF 1st MATRIX\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&x[i][j]);
}
printf("ENTER ELEMENTS OF 2nd MATRIX\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&y[i][j]);
}
printf("MATRIX [X]");
for(i=0;i<3;i++)
{
printf("\n\n");
for(j=0;j<3;j++)
printf(" %d",x[i][j]);
}
printf("\nMATRIX [Y]");
for(i=0;i<3;i++)
{
printf("\n\n");
for(j=0;j<3;j++)
printf(" %d",y[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
z[i][j]=x[i][j]+y[i][j];
}
printf("\nMATRIX [Z]");
for(i=0;i<3;i++)
{
printf("\n\n");
for(j=0;j<3;j++)
printf(" %d",z[i][j]);
}
getch();
}


Output

ADDITION OF TWO MATRIX IN C

FIND THE ASCII VALUE OF A GIVEN NUMBER

FIND THE ASCII VALUE OF A GIVEN NUMBER

Find ASCII Value of a Given Number in C

#include <stdio.h>
#include <ctype.h>
#include<conio.h>
int main(void)
{
int number, result;
clrscr();
textcolor(2);
cprintf("ENTER ANY NUMBER = ");
number = getch();
printf("%c",number);
result = toascii(number);
printf("\n\nASCII VALUE OF %c IS %d\n", number, result);
getch();
return 0;
}




Output

FIND THE ASCII VALUE OF A GIVEN NUMBER