Sei sulla pagina 1di 35

C program to check odd or even

#include<stdio.h>
#include<conio.h>

void main()
{
int no;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
if(no%2==0)
{
printf("Even num");
}
else
{
printf("Odd num");
}
getch();
}

C Program to Swap two numbers using third variables

Swap Two Numbers Program in C


#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c;
clrscr();
printf("Enter value of a: ");
scanf("%d",&a);
printf("Enter value of b: ");
scanf("%d",&b);
c=a;
a=b;
b=c;
printf("After swapping a=: %d b=: %d",a,b);
getch();
}

C Program to Swap two numbers without using third variable

Swap Two Numbers Program in C


#include<stdio.h>
#include<conio.h>

void main()
{
int a,b;
clrscr();
printf("Enter value of a: ");
scanf("%d",&a);
printf("Enter value of b: ");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("After swapping \na=: %d\nb=: %d",a,b);
getch();
}

A Prime number is a natural number greater than 1 that has no positive divisors other than 1 and
itself. It is only divisible by 1 and itself, and it start from 2. The smallest prime number is 2.

Prime number program in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i,no;
clrscr();
printf("Enter any num: ");
scanf("%d",&no);
if(no==1)
{
printf("Smallest Prime no. is 2");
}
for(i=2;i<no;i++)
{
if(no%i==0)
{
printf("Not Prime no.");
break;
}
}
if(no==i)
{
printf("Prime no.");
}
getch();
}

Print next prime number in C


When we enter any number this code will print next Prime number.
Example: Suppose we enter 5 then next prime number is 7.

C program to print next prime number


#include<stdio.h>
#include<conio.h>

void main()
{
int i,j=2,num;
clrscr();
printf("Enter any no.: ");
scanf("%d",&num);
printf("Next Prime no.: ");
for(i=num+1; i<3000; i++)
{
for(j=2; j<i; j++)
{
if(i%j==0)
{
break;
} // if
} // for
if(i==j || i==1)
{
printf("%d\t",i);
break;
} // if
} // outer for
getch();
}

C Program for calculator


Calculator Program in C
#include<stdio.h>
#include<conio.h>

void main()
{
char choice;
int a,b,res=0;
clrscr();
printf("Enter First value: ");
scanf("%d",&a);
printf("\n Enter Operator: ");
choice=getch();
printf("\n Enter Second value: ");
scanf("%d",&b);

switch(choice)
{
case '+':
res=a+b;
printf("Sum: %d",res);
break;
case '-':
res=a-b;
printf("Difference: %d",res);
break;
case '*':
res=a*b;
printf("Product: %d",res);
break;
case '/':
res=a/b;
printf("Quotient: %d",res);
break;
default:
printf("Enter Valid Operator!!");
}
getch();
}

Factorial of any number is the product of an integer and all the integers below it.For example
factorial of 4 is
4! = 4 * 3 * 2 * 1 = 24

Factorial of a given number using for loop

Factorial of Number Program in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i, no, fact=1;
clrscr();
printf("Enter the any no. : ");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
fact=fact*i;
}
printf("Factorial =%d ",fact);
getch();
}

Find table of any number

Find Table of any Number in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i,no,table=1;
clrscr();
printf("Enter any number : ");
scanf("%d",&no);
printf("Table of %d \n",no);
for(i=1;i<=10;i++)
{
table=no*i;
printf("%d",table);
printf("\n");
}
getch();
}

Reverse of number means reverse the position of all digits of any number. For example reverse
of 839 is 938

C Program to Reverse any Number Using While Loop


#include<stdio.h>
#include<conio.h>

void main()
{
int no,rev=0,r,a;
clrscr();
printf("Enter any num: ");
scanf("%d",&no);
a=no;
while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;
}
printf("Reverse of %d is: %d",a,rev);
getch();
}

Find number of Digits


This code is correct when user enter +ve numbers Only.

Find Number of Digits of Any Numbers in C


#include<stdio.h>
#include<conio.h>

void main()
{
int no,a=0;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
while(no>0)
{
no=no/10;
a++;
}
printf("Number of digits in given number is: %d",a);
getch();
}

Fibonacci Series Program in C


Fibonacci series is in the form of 0, 1, 1, 2, 3, 5, 8, 13, 21,...... To find Fibonacci series you need
to add two previous terms/digits and get next term/number.

Print fibonacci series


#include<stdio.h>
#include<conio.h>

void main()
{
int i,no, first=0, second=1, next;
clrscr();
first=0;
second=1;
printf("Enter nubmer of terms for Series: ");
scanf("%d",&no);
printf("Fibonacci series are:\n");
for(i=0; i<no; i++)
{
printf("%d\n",first);
next = first + second;
first = second;
second = next;
}
getch();
}

C Program to check Armstrong or Not


A Armstrong number is a number that is the sum of its own digits each raised to the power of
the number of digits is equal to the number itself.

For example:
Three Digits Armstrong number is 153, 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 153
Four Digits Armstrong number is 1634, 1 ^ 4 + 6 ^ 4 + 3 ^ 4 + 4 ^ 4 + = 1634

3 Digits Armstrong number


Armstrong number program in C
#include<stdio.h>
#include<conio.h>

void main()
{
int temp, arm=0,a,b,c,d,num;
clrscr();
printf("Enter any number: ");
scanf("%d",&num);
temp=num;
while(temp>0)
{
a=temp%10;
temp=temp/10;
arm=arm+a*a*a;
}
if(arm==num)
{
printf("%d is armstrong number",num);
}
else
{
printf("%d is not armstrong number", num);
}
getch();
}

Find largest number using if-else

Find Largest Number Program in C


#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c;
clrscr();
printf("Enter any three number: ");
scanf("%d%d%d",&a,&b,&c);

if(a >= b && a >= c)


printf("%d is largest",a);
else if(b >= a && b >= c)
printf("%d is largest",b);
else if(c >= a && c >= b)
printf("%d is largest",c);
getch();
}

Find Largest Number Program in C


#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c,largest;
clrscr();
printf("Enter any three numbers: ");
scanf("%d%d%d",&a,&b,&c);
largest=(a>b)?(a>c?a:c):(b>c?b:c);
printf("Largest number: %d",largest);
getch();
}

A palindrome number is a number that remains the same when its digits are reversed. Like
16461, for example: we take 121 and reverse it, after revers it is same as original number.

Steps to write program for Palindrome Number


Get the number from user.
Reverse it.

Compare it with the number entered by the user.

If both are same then print Given number is palindrome Number

Else print not palindrome number.

Find palindrome number using for loop

Check Number is Palindrome or not in C


#include<stdio.h>
#include<conio.h>

void main()
{
int a,no,b,temp=0;
clrscr();
printf("Enter any num: ");
scanf("%d",&no);
b=no;
for(;no>0;)
{
a=no%10;
no=no/10;
temp=temp*10+a;
}
if(temp==b)
{
printf("Palindrome number");
}
else
{
printf("Not Palindrome number");
}
getch();
}

Find HCF of Two Numbers Program in C


Suppose find HCF of 4 and 8
4=4*1=2*2
8=8*1=2*4=2*2*2
Factor of 4 is 1, 2, 4
Factor of 8 is 1, 2, 4, 8
So, common factor of 4 and 8 is 1, 2, 4
and highest common factor is 4
hcf of 4 and 8 is: 4

program to find hcf of two numbers


#include<stdio.h>
#include<conio.h>

void gcd(int,int);

void main()
{
int a,b;
clrscr();
printf("Enter two numbers: ");
scanf("%d %d",&a,&b);
gcd(a,b);
getch();
// return 0;
}

//function to calculate g.c.d


void gcd(int a,int b)
{
int m,n;

m=a;
n=b;

while(m!=n)
{
if(m>n)
m=m-n;
else
n=n-m;
}

printf("\nH.C.F of %d and %d is: %d",a,b,m);


}

Find LCM of Two Numbers Program in C


To find the LCM (Least Common Multiple) of two or more numbers, make multiple of
numbers and choose common multiple. Then take lowest common multiple, this lowest common
multiple is LCM of numbers. For example;

Example
Suppose find LCM of 3 and 4
Multiple of 3 : 3, 6, 9, 12, 15, 18, 21, 24,.......
Multiple of 4 : 4, 8, 12, 16, 20, 24, 28,.....

So, common multiple of 3 and 4 is 12, 24


and Least Common Multiple is 12
LCM of 3 and 4 is: 12

C Program to Find LCM of Two Number


#include<stdio.h>
#include<conio.h>

void lcm(int,int);

void main()
{
int a,b;
clrscr();
printf("Enter two numbers: ");
scanf("%d %d",&a,&b);
lcm(a,b);
getch();
// return 0;
}

//function to calculate l.c.m


void lcm(int a,int b)
{
int m,n;

m=a;
n=b;

while(m!=n)
{
if(m < n)
{
m=m+a;
}
else
{
n=n+b;
}
}

printf("\nL.C.M of %d and %d is: %d",a,b,m);


}

Find Square Root of Any Number Program in C


For calculate square root of any number we multiply number by 0.5 because square root of any
number means power of 1/2 and 1/2=0.5.

Find Square Root of Any Number Program in C


#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int num,ans;
clrscr();
printf("Enter any number: ");
scanf("%d",&num);
ans=pow(num,0.5);
printf("\n Square root of %d is: %d",num,ans);
getch();
}

Find Cube Root of Any Number Program in C


To find cube root of any number we need to find 1/3 power of any number. For example if you
need to find cube root of 27 then calculate 1/3 power of 27, result is 3.
Find Cube Root of Any Number Program in C
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int num, ans;
clrscr();
printf("Enter any number: ");
scanf("%d",&num);
ans=pow(num, 1.0/3.0);
ans++;
printf("\n\Cube of %d is: %d",num,ans);
getch();
}

Find Ascii Value of Any Number Program in C


Full form of Ascii is American Standard Code for Information Interchange. Ascii is a
character-encoding scheme. Originally based on the English alphabet, every character or number
have its own Ascii value for example Ascii value of a is 97.

Find Ascii Value of Number using Library Function


C Program to Find Ascii Value of Number
#include<stdio.h>
#include<ctype.h>
#include<conio.h>

int main(void)
{
int number, result;
clrscr();
printf("Enter any Character/Symbol/Digits: ");
number = getch();
result = toascii(number);
printf("\nAscii value of %c is %d\n", number, result);
getch();
}

Calculate Sum of Digits C Programs


Sum Of Digits means add all the digits of any number, for example we take any number like 358.
Its sum of digits is 3+5+8=16. Using given code we can easily find sum of digits of any number.
Program to calculate sum of digits
#include<stdio.h>
#include<conio.h>

void main()
{
int a,no,sum=0;
clrscr();
printf("Enter any number: ");
scanf("%d",&no);
while(no>0)
{
a=no%10;
no=no/10;
sum=sum+a;
}
printf("\nSum of Digits: %d",sum);
getch();
}

program to check lower and upper case


islower(): Function is used to check character in lower case or not.
isupper(): Function is used to check character in upper case or not.
isdigit(): Function is used to check character in digit or not.

program to check lower and upper case


#include<stdio.h>
#include<conio.h>
#include<ctype.h>

void main()
{
char ch;
clrscr();
printf("Enter any charecter: ");
scanf("%c",&ch);
if(islower(ch))
{
printf("\n Lower case small letter");
}
else if(isupper(ch))
{
printf("Upper case capital letter");
}
else if(isdigit(ch))
{
printf("This number or digit");
}
else
{
printf("This is speciial symbol");
}
getch();
}

Program to Check Leap Year in C


A leap year is a year containing one additional day that means in leap year 366 day. and leap year
are divisible by 4 so if you write any program to check leap year check year must be divisible by
4.

Program to check leap year


#include<stdio.h>
#include<conio.h>

void main()
{
int y;
printf("Enter any year: ");
scanf("%d",&y);
if(y%4==0)
{
printf("Leap year");
}
else
{
printf("Not a leap year");
}
getch();
}

Find Area of Circle Program in C


For calculate area of circle you need radius of circle and apply below formula;

Formula
area of circle = 3.14*(radius*radius);

program to find area of circle


#include<stdio.h>
#include<conio.h>

void main()
{
int radius;
float area_circle=0;
clrscr();
printf("Enter radius of circle: ");
scanf("%d",&radius);
area_circle=3.14*(radius*radius);
printf("\nArea of Circle: %f",area_circle);
getch();
}

Find Area of Rectangle Program in C


For calculate area and parameter of rectangle you need length and breath of rectangle and apply
below formula;

Formula
Area of Rectangle = length*breath;
Parameter of Rectangle = 2*(length+breath);

program to find area of rectangle


#include<stdio.h>
#include<conio.h>

void main()
{
int length,breath,area_rec=0,parameter=0;
clrscr();
printf("Enter Length and Breath of Rectangle: ");
scanf("%d%d",&length,&breath);
area_rec=length*breath;
parameter=2*(length+breath);
printf("\nArea of Ractangle: %d",area_rec);
printf("\nParameters of Rectangle: %d",parameter);
getch();
}

Calculate Percentage of Marks Program in C


For calculate percentage of marks obtained by student, divide total marks by number of subject
( percentage=total marks / number of subject ).

Algorithm to calculate percentage


First received marks of each subject.
Calculate sum of all subjects marks.

divide total marks by number of subject (percentage=total marks / number of subject).


Finally print percentage on screen.

Program to calculate percentage of marks


#include<stdio.h>
#include<conio.h>

void main()
{
int no, i;
float marks[10], per=0, total=0;
clrscr();
printf("Enter number of subject: ");
scanf("%d",&no);
printf("Enter marks of %d subject: ",no);
for(i=0; i<no; i++)
{
scanf("%f",&marks[i]);
}
for(i=0; i<no; i++)
{
total=total+marks[i];
}
per=total/no;
printf("Percentage: %f %",per);
getch();
}

Calculate Grade of Student Program in C


Write a C program to calculate grade of student, If percentage > 85 print A grade, If percentage
<85 print B grade, If percentage <75 print C grade, If percentage <50 print D grade, If
percentage <30 print fail."

Algorithm to calculate grade


First received marks of each subject.
Calculate sum of all subjects marks.

divide total marks by number of subject (percentage=total marks / number of subject).

If percentage > 85 print A grade, If percentage < 85 && percentage >= 75 print B grade, If
percentage < 75 && percentage >= 50 print C grade, If percentage > 30 && percentage <= 50
print D grade, If percentage <30 print fail

Finally print percentage on screen.

Program to calculate grade of student


#include<stdio.h>
#include<conio.h>
void main()
{
int no, i;
float marks[10], per=0, total=0;
clrscr();
printf("Enter number of subject: ");
scanf("%d",&no);
printf("Enter marks of %d subject: ",no);
for(i=0; i<no; i++)
{
scanf("%f",&marks[i]);
}
for(i=0; i<no; i++)
{
total=total+marks[i];
}
per=total/no;
printf("Percentage: %f % \n",per);
if(per>85) {
printf("A grade");
}
else if(per<85 && per>=75)
{
printf("B grade");
}
else if(per<75 && per>=50)
{
printf("C grade");
}
else if(per<50 && per>=30)
{
printf("D grade");
}
else
{
printf("Fail");
}
getch();
}

Count length of string without using any library function.


Find length of string
#include<stdio.h>
#include<conio.h>

void main()
{
int i,count=0;
char ch[20];
clrscr();
printf("Enter Any string: ");
gets(ch);
for(i=0;ch[i]!='\0';i++)
{
count++;
}
printf("Length of String: %d",count);
getch();
}

To compare any two string first we need to find length of each string and then compare both
strings. If both string have same length then comapre character by character of each string.

Program to compare two string


#include<stdio.h>
#include<conio.h>

void main()
{
char str1[20],str2[20],i,j,flag=0;
clrscr();
printf("Enter first string: ");
gets(str1);
printf("Enter Second string: ");
gets(str2);
i=0;
j=0;
while(str1[i]!='\0')
{
i++;
}
while(str2[j]!='\0')
{
j++;
}
if(i!=j)
{
flag=0;
}
else
{
for(i=0,j=0;str1[i]!='\0',str2[j]!='\0';i++,j++)
{
if(str1[i]==str2[j])
{
flag=1;
}
}
}
if(flag==0)
{
printf("Strings are not equal");
}
else
{
printf("Strings are equal");
}
getch();
}

Reverse any String Program in C


Reverse of String means reverse the position of all character of any String. For example reverse
of porter is retrop.

Program to Reverse any String in C


#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
char str[100],temp;
int i,j=0;
clrscr();
printf("Enter any the string :");
gets(str); // gets function for input string
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
printf("Reverse string is :%s",str);
getch();
}

Program to concatenate two string


Combined two string means add both string with each other, we can perform this operation using
library function or without library function. For example if first string is john and second string
is porter then after combined these string output is johnporter.

program combined two string


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *ch1="john ";
char *ch2="porter";
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);
getch();
}

Copy First String into Second String Program in C


C Program to Copy First String into Second String
#include<stdio.h>
#include<conio.h>

void main()
{
char s1[100], s2[100], i;
clrscr();
printf("Enter string s1: ");
scanf("%s",s1);
for(i=0; s1[i]!='\0'; ++i)
{
s2[i]=s1[i];
}
s2[i]='\0';
printf("String s2: %s",s2);
getch();
}

Find Sum of Array Elements Program in C


Sum of all Array elements means add all array Elements. Suppose we have 4 Elements in array
and we want to find there sum.
arr[0]=4
arr[1]=2
arr[2]=1
arr[3]=6
Sum off all above elements are
arr[0]+arr[1]+arr[2]+arr[3]=4+2+1+6=13

Find Sum of Array Elements Program in C


#include<stdio.h>
#include<conio.h>
void main()
{
int arr[20],i,n,sum=0;
clrscr();
printf("How many elements you want to enter: ");
scanf("%d",&n);
printf("Enter any %d elements in Array: ",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Sum of Array Elements: ");

for(i=0;i<n;i++)
{
sum=sum+arr[i];
}
for(i=0;i<n;i++)
{
}
printf("%d ",sum);
getch();
}

program to find even and odd array elements


#include<stdio.h>
#include<conio.h>

void main()
{
int arr[20],even[20],odd[20],i,j=0,k=0,no;
clrscr();
printf("Enter size of array: ");
scanf("%d",&no);
printf("Enter any %d elements in Array: ",no);
for(i=0; i<no;i++)
{
scanf("%d",&arr[i]);
}
for(i=0; i<no;i++)
{
if(arr[i]%2==0)
{
even[j]=arr[i];
j++;
}
else
{
odd[k]=arr[i];
k++;
}
}
printf("\nEven Elements: ");
for(i=0; i<j ;i++)
{
printf("%d ",even[i]);
}
printf("\nOdd Elements: ");
for(i=0; i<k; i++)
{
printf("%d ",odd[i]);
}
getch();
}

C Program to Print Patterns of numbers


#include<stdio.h>
#include<conio.h>

void main()
{
int i,j, k=1;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<i;j++)
{
printf("%d",k);
k++
}
printf("\n");
}
getch();
}

Output
1
23
456
78910

C Program to Print Patterns of numbers


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}

getch();
}

Output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Print number Pattern in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i,j,k;
k=1;
for(i=1;i<=5;i+=2)
{
for(j=5;j>=1;j--)
{
if(j>i)
printf(" ");
else
printf("%d ",k++);
}
printf("\n");
}
getch();
}

Output
1
2 3 4
5 6 7 8 9

C Program to Print Patterns of numbers


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
clrscr();
for(i=1;i<=7;i+=2)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
for(i=5;i>=1;i-=2)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
getch();
}

Output
1
123
12345
1234567
12345
123
1

Example
#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
printf("%d",i);
printf("\n");
}
getch();
}

Output
11111
22222
33333
44444
55555
Example
#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
clrscr();
for(i=5;i>=1;i--)
{
for(j=5;j>=1;j--)
{
if(j>i)
printf(" ");
else
printf("%d",j);
}
printf("\n");
}
getch();
}

Output
54321
4321
321
21
1

print number pattern


#include<stdio.h>
#include<conio.h>

void main()
{
int n, c, d, num = 1, space;
clrscr();
printf("Enter any number (1-10): ");
scanf("%d",&n);
space=n-1;
for(d=1; d<=n; d++)
{
num=d;
for(c=1; c<=space; c++)
printf(" ");
space--;
for(c=1; c<=d; c++)
{
printf("%d", num);
num++;
}
num--;
num--;
for(c=1; c<d; c++)
{
printf("%d", num);
num--;
}
printf("\n");
}
getch();
}

Output
Enter any number (1-10): 4
1
232
34543
4567654

Print star triangle in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i,j,k;
clrscr();
for(i=1; i<=5; i++)
{
for(j=4; j>=i; j--)
{
printf(" ");
}
for(k=1; k<=(2*i-1); k++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
Print Star Pattern in C
#include<stdio.h>
#include<conio.h>

void main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

Print * Triangle in C
#include<stdio.h>
#include<conio.h>

void main()
{
int i,j;
clrscr();
for(i=1; i<=6; i++)
{
for(j=1; j<i; j++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output
*
* *
* * *
* * * *
* * * * *

print star triangle


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output
* * * * *
* * * *
* * *
* *
*

print * pattern
#include<stdio.h>
#include<conio.h>

void main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(k=5;k>=i;k--)
{
printf("*");
}
printf("\n");
}
getch();
}

Output
*
* *
* * *
* * * *
* * * * *

print star triangle


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output
* * * * *
* * * *
* * *
* *
*

print dimond of star


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*

Print Alphabet Pattern in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%c",'A' + j-1);
}
printf("\n");
}
getch();
}

Output
A
AB
ABC
ABCD
ABCDE

Print Alphabet Pattern in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%c",'A'-1 + i);
}
printf("\n");
}
getch();
}

Output
A
BB
CCC
DDDD
EEEEE

C Program to Print Alphabet Pattern


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
printf("%c",'A'-1 + i);
}
printf("\n");
}
getch();
}

Output
AAAAA
BBBB
CCC
DD
E

Program to Print Alphabet Pattern in C


#include<stdio.h>
#include<conio.h>

void main()
{
char s[]="india";
int i,j;
clrscr();
for(i=0;s[i];i++)
{
for(j=0;j<=i;j++)
printf("%c",s[j]);
printf("\n");
}
getch();
}

Output
I
IN
IND
INDI
INDIA

Print Alphabet Pattern Program in C


#include<stdio.h>
#include<conio.h>

void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(j%2==0) printf("A");
else printf("*");
}
printf("\n");
}
getch();
}

Output
*
*A*
*A*A*
*A*A*A*

C program to Calculate 1 + 2 + 3 + 4 + 5 + ... + n series


Program to Print Number Series in C
#include<stdio.h>
#include<conio.h>

void main()
{
int i,n,sum=0;
clrscr();
n=10;
for(i=1;i<=n;i++)
{
sum+=i;
}
printf("Sum: %d",sum);
getch();
}

Output
Sum: 55

C program to Calculate (1*1) + (2*2) + (3*3) + (4*4) + (5*5)


+ ... + (n*n) series
Program to Print Number Series in C
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
n=10;
for(i=1;i<=n;i++)
{
sum+=i*i;
}
printf("Sum: %d",sum);
getch();
}

Output
Sum: 385

C program to Calculate (1) + (1+2) + (1+2+3) + (1+2+3+4)


+ ... + (1+2+3+4+...+n) series
Print Number Series
#include<stdio.h>
#include<conio.h>

void main()
{
int i,j,n,sum=0;
clrscr();
n=10;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
sum+=j;
}
}
printf("Sum: %d",sum);
getch();
}

Output
Sum:385

Program to Print Pascal Triangle in C


#include<stdio.h>
#include<conio.h>

void main()
{
int bin,p,q,r,x;
clrscr();
bin=1;
q=0;
printf("\t\t\tDisplay pascal Triangle");
printf("\n\n\t\t Created By:- Hitesh Kumar");
printf("\n\n\nHow Many Row Do you want to input:");
scanf("%d",&r);

printf("\nPascal's Triangle:\n");

while(q<r)
{
for(p=40-3*q;p>0;--p)
printf(" ");
for(x=0;x<=q;++x)
{
if((x==0)||(q==0))
bin=1;
else
bin=(bin*(q-x+1))/x;
printf(" ");
printf("%d",bin);
}

printf("\n\n\n");
++q;
}
getch();
}

Potrebbero piacerti anche