#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 simple programs. Show all posts
Showing posts with label simple programs. 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
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 Power Of A Number in C
#include<stdio.h>
#include<conio.h>
void main()
{
long int a,b,c,i,j,d,u;
clrscr();
printf("enter base =");
scanf("%ld",&a);
u=a;
printf("\nenter exponent =");
scanf("%ld",&b);
for(i=0;i<b;i++)
{
c=a*u;
a=c;
}
if(b==1)
{
c=c/u;
}
printf("%ld",c);
getch();
}
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();
}
Prime Numbers in C
#include<stdio.h>
#include<conio.h>
void main()
{
int num2,num1,c,i;
clrscr();
printf("enter the starting number =");
scanf("%d",&num1);
printf("\n\nenter the ending number =");
scanf("%d",&num2);
for(i=num1;i<=num2;i++)
{
for(c=2;c<=i-1;c++)
{
if(i%c==0)
break;
}
if(i==c)
{
printf("\n\n%d",i);
}
}
getch();
}
Thursday, 12 July 2012
Print Right Angle Triangle Shape in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=10;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
To Reverse Two Numbers in C
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("\n\nenter a number");
scanf("%d",&a);
b=a%10;
c=a/10;
printf("%d",b);
printf("%d",c);
getche();
}
Print Greater Or Smaller Number in C
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the value of a");
scanf("%d",&a);
printf("enter the value of b");
scanf("%d",&b);
if (a>b);
{
printf("a is greater than b");
printf("b is less than a");
}
if (a<b);
{
printf("b is greater than a");
printf("a is less than b");
}
getch;
}
Print Even Or Odd in C
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\n\nenter a number=");
scanf("%d",&a);
if(a%2==0)
{
printf("\n\ngiven number is even");
}
if (a%2==1)
{
printf("\ngiven number is ood");
}
getch();
}
Subscribe to:
Posts (Atom)