#include<stdio.h>#include<conio.h> void main() { if(printf("Hello world")) { } getche(); }
This website is designed to provide you all codes of C and C++ language and also tutorials for learn the concept of these languages.
Showing posts with label cprogramming. Show all posts
Showing posts with label cprogramming. Show all posts
Saturday, 4 August 2012
To Print A statement without Using Semicolon
To print Floyd’s triangle in C language
void main()
{
int i,j,num;
int k=1;
printf("Enter the value of range == ");
scanf("%d",&num);
printf("FLOYD's Triangle\n");
for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++,k++)
{
printf(" %d",k);
}
printf("\n");
}
getche();
}
Friday, 3 August 2012
Print Composite Numbers in C
#include <stdio.h>
#include<conio.h>
void composite(int x);
void main()
{
int a;
printf("how much composite number you want to generate = ");
scanf("%d",&a);
composite(a);
getche();
}
void composite(int x)
{
int counter=0,number=0,i=1,j;
while(number<x)
{
counter=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
counter++;
}
if(counter>2)
{
printf("%d ",i);
number++;
}
i++;
}
}
Find The Largest Number Among Three
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,large;
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
large=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is: %d",large);
getche();
}
Find Power of A Number in C
#include<stdio.h>
#include<conio.h>
void main()
{
int pow,num,i=1;
unsigned long int sum=1;
printf("\nEnter your number == ");
scanf("%d",&num);
printf("\nEnter the desired power ==");
scanf("%d",&pow);
while(i<=pow)
{
sum=sum*num;
i++;
}
printf("\n%d to the power %d is: %ld",num,pow,sum);
getche();
}
Monday, 23 July 2012
String Catenation Without Using Strcat Function in C
#include<conio.h>
#include<stdio.h>
void stringconcatenation(char[],char[]);
void main()
{
char str1[100],str2[100];
int compare;
printf("Enter the first string: ");
gets(str1);
printf("Enter the second string: ");
gets(str2);
stringconcatenation(str1,str2);
printf(" The String after concatenation: %s",str1);
getch();
}
void stringconcatenation(char str1[],char str2[])
{
int i=0,j=0;
while(str1[i]!='\0')
{
i++;
}
while(str2[j]!='\0')
{
str1[i] = str2[j];
i++;
j++;
}
str1[i] ='\0';
}
#include<stdio.h>
void stringconcatenation(char[],char[]);
void main()
{
char str1[100],str2[100];
int compare;
printf("Enter the first string: ");
gets(str1);
printf("Enter the second string: ");
gets(str2);
stringconcatenation(str1,str2);
printf(" The String after concatenation: %s",str1);
getch();
}
void stringconcatenation(char str1[],char str2[])
{
int i=0,j=0;
while(str1[i]!='\0')
{
i++;
}
while(str2[j]!='\0')
{
str1[i] = str2[j];
i++;
j++;
}
str1[i] ='\0';
}
Thursday, 19 July 2012
Fibonaaci Series in C
#include<stdio.h>
#include<conio.h>
int main(void)
{
int n,a=0,b=1,c=0,i=1;
printf("How Mnay First Fibonacci Numbers you Want To Generate?\t\t");
scanf("%d",&n);
printf("%d %d",a,b);
while(i<=n-2)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
i++;
}
getch();
return 0;
}
Saturday, 14 July 2012
Recursion: Program to Convert Decimal To Binary
# include <stdio.h>
#include <conio.h>
void Dec_To_Bin (int num);
void main ()
{
int num;
int base;
clrscr();
printf ("Enter the decimal number to convert it binary.\n");
scanf ("%d", &num);
printf ("The %d in binary is : ", num);
Dec_To_Bin (num);
getch();
}
void Dec_To_Bin (int num)
{
if (num > 1)
{
Dec_To_Bin ((num / 2));
}
printf ("%d", (num % 2));
}
Program To Convert Octal To Binary
#include<stdio.h>
#include<conio.h>
#include<math.h>
float octal_conversion(int octal);
void main()
{
int octal,answer;
clrscr();
printf("program which convert octal to decimal\n\n");
printf("Enter a number in octal form= ");
scanf("%d",&octal );
answer = octal_conversion(octal);
if(answer == 8)
{
printf("wrong");
}
else
{
printf("The result is %d", answer);
}
getch();
}
float octal_conversion(int octal)
{
int square;
int remainder;
int i = 0;
int result=0 ;
while(octal > 0)
{
remainder = octal % 10;
square=pow(8,i);
if(remainder<=7)
{
result = result + square * remainder;
}
else
{
return 8;
}
octal = octal / 10;
i++;
}
return result;
}
Calculate HCF in C
#include<stdio.h>
#include<conio.h>
int hcf(int n1 ,int n2);
void main()
{
int n1,n2;
clrscr();
printf("enter the two number =");
scanf("\n%d\n%d",&n1 ,&n2);
printf("\n HCF of two numbers is =%d",hcf(n1,n2));
getch();
}
int hcf(int n1 ,int n2)
{
int i,minimum,u;
if (n1>n2)
{
minimum=n2;
}
else
{
minimum=n1;
}
for(i=minimum;i>=1;i--)
{
if(n1%i==0 && n2%i==0)
{
u=i;
return u;
}
}
}
Friday, 13 July 2012
Calculate LCM in C
#include<stdio.h>
#include<conio.h>
int lcm(int n1,int n2);
void main()
{
int n1,n2,x,y;
clrscr();
printf("\nEnter two numbers:");
scanf("%d %d",&n1,&n2);
printf("L.C.M is=%d",lcm(n1,n2));
getch();
}
// Function Definition
int lcm(int n1,int n2)
{
int x,y,u;
x=n1,y=n2;
while(n1!=n2)
{
if(n1>n2)
{
n1=n1-n2;
}
else
{
n2=n2-n1;
}
}
u=(x*y)/n1;
return u;
}
Calculate Factorial in C
#include<stdio.h>
#include<conio.h>
void main()
{
long int multiply,num;
long int i=0,a,value,sum;
clrscr();
printf("enter number which you find the factorial =");
scanf("%ld",& num);
multiply=num;
value=num;
a=num-1;
while(i++<a)
{
sum=value-i;
multiply=multiply*sum;
}
printf("%ld",multiply);
getche();
}
Thursday, 12 July 2012
Check Palindrome in C
#include <stdio.h>
#include <string.h>
void main()
{
char string[20];
int i, j, length=0, flag=0;
printf("\nEnter The desired String string: ");
gets(string);
for (i=0; string[i]!='\0'; i++)
{
length++;
i = 0;
j = length-1;
while (i < length)
{
if (string[i] != string[j])
{
flag = 1;
break;
}
i++;
j--;
}
if (flag == 0)
{
printf("\n Your Desired String is palindrome");
}
else
{
printf("\nYour Desired String is not palindrome");
}
getch();
}
Pirnt BOX shape in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a,b,c,d;
char hamza;
clrscr();
printf("enter height");
scanf("%d",&a);
printf("enter your desire symbol =");
hamza=getche();
clrscr();
b=a+a;
c=b/2;
d=c+1;
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
if((j==1)||(j==c)||(j==d)||(j==b)||(i==1)||(i==a))
{
printf("%c",hamza);
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}
Print Alphabet "B" in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,e,l;
clrscr();
e=6/2;
l=e+1;
for(i=1;i<=6;i++)
{
for(j=1;j<=6;j++)
{
if((j==1)||(j==6)||(i==1)||(i==6)||(i==l))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}
Calculate Average in C
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
clrscr;
printf("enter the value of a");
scanf("%d",&a);
printf("enter the value of b");
scanf("%d",&b);
printf("enter the value of c");
scanf("%d",&c);
printf("enter the value of d");
scanf("%d",&d)
e=(a+b+c+d)/4; // Average Formula
printf("%d",e);
getch;
}
Wednesday, 11 July 2012
Print Alphabet "I" in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,p,a;
clrscr();
printf("enter the height =");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
printf("*\n");
}
getch();
}
Print Alphabet "I" in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,p,a;
clrscr();
printf("enter the height =");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
printf("*\n");
}
getch();
}
Print Alphabet "L" in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,p,a;
clrscr();
printf("enter the height =");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
printf("*\n");
}
if(i==a+1)
{
for(p=1;p<=a;p++)
{
printf("*");
}
}
getch();
}
Print Alphabet "M" in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,b,a,r,g;
clrscr();
printf("enter height =");
scanf("%d",&a);
r=a+a;
g=r-1;
b=a+(a-1);
for(i=1;i<=a;i++)
{
for(j=0;j<=b;j++)
{
if((j==1)||(i==j)||(j==g)||(i==a-j+a))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}
Subscribe to:
Posts (Atom)