NOTICE :-
kindly do practice in visual Studio code for better performance
Write a Program to print hello wordl!
# include <stdio.h>
int main()
{
printf("Welcome to the World of C
Programming.");
return 0;
}
Write a C Program to print Book Details like Book Id, Book Title,
AuthorName, PublisherName, Price etc.
# include <stdio.h>
int main()
{
printf("\t\t\t\tBook Information");
printf("\nBook Name:Programming in ANSI
C");
printf("\nAuthor Name:E
Balagurusamy");
printf("\nPublisher Name:");
printf("\nPrice:250.00");
return 0;
}
Write a C Program to print the following string. (Use of Escape Sequence
for “ ” DOUBLE QUATE) Someone Said “Nothing is Impossible in this World”.
# include <stdio.h>
int main()
{
printf("Someone Said:\"Nothing Is
Impossible In This World.\" ");
return 0;
}
Write a C Program to print the following string. (Use
of Escape Sequence for ‘ ’ SINGLE QUATE) Someone Said ‘God is Great’.
# include <stdio.h>
int main()
{
printf("Someone Said \'God Is Great.\'");
return 0;
}
Write a program that will read two numeric values
& print those values.
# include <stdio.h>
int main()
{
int no;
printf("Enter
any Number:");
scanf("%d",&no);
printf("\nNumber=%d",no);
return 0;
}
Write a C Program to accept Dollar and convert it into
Rupees. (1 Dollar = 79.81 Rupees)
# include <stdio.h>
int main()
{
int Dollar,
Rupees;
printf("Enter
Dollar:");
scanf("%d",&Dollar);
Rupees =Dollar*45;
printf("\nRupees=%d",Rupees);
printf("\nDollar=%d",Dollar);
return 0;
}
Write a C program to accept Rupees and convert it into
Paise. (1 rupees = 100 paise)
# include <stdio.h>
int main()
{
int Rupees,Paise;
printf("Enter
Rupees:");
scanf("%d",&Rupees);
Paise=Rupees*100;
printf("Paise=%d",Paise);
printf("\nRupees=%d",Rupees);
return 0;
}
Write a C program to get Liter and convert it into
MiliLiter. (1 Liter= 1000 MiliLiter)
# include <stdio.h>
int main()
{
int Liter,Mililiter;
printf("Enter
Liter:");
scanf("%d",&Liter);
Mililiter=Liter*1000;
printf("Mililiter=%d",Mililiter);
printf("\nLiter=%d",Liter);
return 0;
}
Write a C program to get Fahrenheit and convert it
into Celsius. ( C=(f-32)/1.8)
# include <stdio.h>
int main()
{
float
celsius,fahrenheit;
printf("Enter
any value for Fahrenheit:");
scanf("%f",&fahrenheit);
celsius=(fahrenheit-32)/1.8;
printf("Celsius=%f",celsius);
return 0;
}
Write a C program to get two values and disply
addition, subtraction, Multiplication and Division.
# include <stdio.h>
int main()
{
int
no1,no2,Addition,Substraction,Multiplication,Division;
printf("Enter
Any Number1:");
scanf("%d",&no1);
printf("Enter
Any Number2:");
scanf("%d",&no2);
Addition=no1+no2;
if(no1 > no2){
Substraction=no1-no2;
}
if (no2 > no1)
{
Substraction=no2-no1;
}
Multiplication=no1*no2;
if(no1 > no2){
Division=no1/no2;
}
if (no2 > no1)
{
Division=no2/no1;
}
printf("\nAddition=%d",Addition);
printf("\nSubstraction=%d",Substraction);
printf("\nMultiplication=%d",Multiplication);
printf("\nDivision=%d",Division);
return 0;
}
Write a C program to accept any number and print its
Square and Cube.
# include <stdio.h>
int main()
{
int no,sqr,cube;
printf("Enter
Any Number:");
scanf("%d",&no);
sqr=no*no;
cube=no*no*no;
printf("\nsquare=%d",sqr);
printf("\ncube=%d",cube);
return 0;
}
Input the ages of three student and print their
average, with a suitable message.
# include <stdio.h>
int main()
{
int n1,n2,n3;
float avg;
printf("Enter
any Number for N1:");
scanf("%d",&n1);
printf("Enter
any Number for N2:");
scanf("%d",&n2);
printf("Enter
any Number for N3:");
scanf("%d",&n3);
avg=(n1+n2+n3)/3 ;
printf("Average=%f",avg);
return 0;
}
Write a C program to accept radius and calculate Area
of Circle and print it.
# include <stdio.h>
int main()
{
float r,circle;
printf("Enter
any Redius:");
scanf("%f",&r);
circle=3.14*r*r;
printf("\n\tCircle=%f",circle);
return 0;
}
Write a C program to get radius and calculate and
diaplay the circumference of a circle.
# include <stdio.h>
int main()
{
float
Circumference,r;
printf("Enter
any redius:");
scanf("%f",&r);
Circumference=2*3.14*r;
printf("\n\tCircumference=%f",Circumference);
return 0;
}
Write a C program to get appropriate inputs and
calculate Simple Interest and display it. (I=PRN/100)
# include <stdio.h>
int main()
{
float
principle,year,rate,interest;
printf("Enter
principle (amount):");
scanf("%f",&principle);
printf("Enter
rate:");
scanf("%f",&rate);
printf("Enter
Number of year:");
scanf("%f",&year);
interest=(principle*year*rate)/100;
printf("Simple Interest=%f",interest);
return 0;
}
Write a C program to accept approprite inputs and
calculate Compound Interest and display it.
# include <stdio.h>
# include <math.h>
int main()
{
float p,r,n,ci;
printf("Enter
P:");
scanf("%f",&p);
printf("Enter
R:");
scanf("%f",&r);
printf("Enter
N:");
scanf("%f",&n);
ci=p*pow(1+r/100,n)-p;
printf("Compound Interest=%f",ci);
return 0;
}
Write a C program to get any two values and swap them
or exchange them. (With the help of third variable)
# include <stdio.h>
int main()
{
int a,b,c;
printf("Enter
any value for A:");
scanf("%d",&a);
printf("Enter
any value for B:");
scanf("%d",&b);
printf("Before Swaping:");
printf("\n\t\tA=%d",a);
printf("\n\t\tB=%d",b);
c=a;
a=b;
b=c;
printf("\n\nAfter Swaping:");
printf("\n\t\tA=%d",a);
printf("\n\t\tB=%d",b);
return 0;
}
Write a C program to get any two values and swap them
or exchange them. (Without using third variable)
# include <stdio.h>
int main()
{
int a,b;
printf("Enter
any value for A:");
scanf("%d",&a);
printf("Enter
any value for B:");
scanf("%d",&b);
printf("\n\nBefore Swaping:");
printf("\n\tA=%d",a);
printf("\n\tB=%d",b);
a=a+b;
b=a-b;
a=a-b;
printf("\n\nAfter Swaping:");
printf("\n\tA=%d",a);
printf("\n\tB=%d",b);
return 0;
}
Employee's basic salary is input through the keyboard.
His dearness allowance is 40% of basic salary, and house rent allowance is 20%
of basic salary. Write a program to calculate his gross salary.
# include <stdio.h>
int main()
{
float gs,ha,da,bs;
printf("Enter
Basic Salary:");
scanf("%f",&bs);
da=bs*40/100;
ha=bs*20/100;
gs=bs-(da+ha);
printf("\n\n\tDearness=%.2f",da);
printf("\n\tHouse=%.2f",ha);
printf("\n\tGross Salary=%.2f",gs);
return 0;
}
The distance between two cities (in Km.) is input
through the keyboard. Write a program to convert and print this distance in
meters, feet,inches and centimeters. (1 KM=1000 Meter, 1 Meter=100 CM, 1
Meter=3.33 Feet, 1 Feet=12 Inch)
# include <stdio.h>
int main()
{
float
km,meter,feet,inches,centimeter;
printf("Enter
the distance in km between two cities:");
scanf("%f",&km);
meter=km*1000;
feet=meter*3.33;
inches=feet/12;
centimeter=meter*100;
printf("\n\n\t\tMeter=%.2f",meter);
printf("\n\t\tFeet=%.2f",feet);
printf("\n\t\tInches=%.2f",inches);
printf("\n\t\tCentimeter=%.2f",centimeter);
return 0;
}
Write a C program to accept price of an item and
clculate 23% depreciation.
# include <stdio.h>
int main()
{
float depre,amt;
printf("Enter
Item Amount:");
scanf("%f",&amt);
depre=amt*23/100;
printf("\n\n\tDepreciation=%f",depre);
return 0;
}
Write a C program to accept sale amount and calulate
7.5% discount.
# include
<stdio.h>
int main()
{
float
amt,discount;
printf("Enter
Item Amount:");
scanf("%f",&amt);
discount=amt*7.5/100;
printf("\n\n\tDiscount=%.2f",discount);
return 0;
}
Write a C program to get Base Salary and quantity and
price of an item sold. Calculate bonus 12.5% of total amount, calculate
commission of 8.5% and also calculate gross salary. Gross Salary=Base
Salary+Bonus+Commission
# include <stdio.h>
int main()
{
float
bs,qua,price,com,bonus,gs;
printf("Enter
Basic Salary,Quantity,Price:");
scanf("%f %f
%f",&bs,&qua,&price);
bonus=qua*price*12.5/100;
com=qua*price*8.5/100;
gs=bs+bonus+com;
printf("\n\tBonus=%f",bonus);
printf("\n\tCommission=%f",com);
printf("\n\tGross Salary=%f",gs);
return 0;
}
Write a C program to accept any real number and store
it inateger part in variable X and fraction part in Y and display them. Input:
n=123.75 Output :x=123 y=75
#include <stdio.h>
int main()
{
float no;
int a, b;
printf("Enter
Any Real Number:");
scanf("%f", &no);
a = no;
b = (no - a) * 100;
printf("\n\tIntegral Part=%d", a);
printf("\n\tFraction Part=%d", b);
return 0;
}
Write a C program that reads a floating-point number
and then displays the right most digit of the integral part of inputted number
# include <stdio.h>
int main()
{
float n;
int a;
printf("Enter
Value:");
scanf("%f",&n);
a=n;
printf("\n\tIntegral Part=%d",a %10);
return 0;
}
Write a C program that will obtain the lenght, breadth
and height of a rectangle from the user and calculate area of rectangle.
(area=lbh)
# include <stdio.h>
int main()
{
long int
Area,l,b,h;
printf("Enter
any value for Length:");
scanf("%ld",&l);
printf("Enter
any value for Breadth:");
scanf("%ld",&b);
printf("Enter
any value for Height:");
scanf("%ld",&h);
Area=l*b*h;
printf("Area=%ld",Area);
return 0;
}
Write a C Program to accept any number and check
whether it is divisible by 9 or not
# include <stdio.h>
int main()
{
int no;
printf("Enter
Any Number:");
scanf("%d",&no);
if(no%9==0)
{
printf("\n\t\tIt Is Divisible Number.");
}
else
{
printf("\n\t\tIt Is Not Divisible Number:");
}
return 0;
}
Write a C program to accept any number and check
whether it is positive or negative Using if...else
# include <stdio.h>
int main()
{
int no;
printf("Enter
Any Number:");
scanf("%d",&no);
if(no>=0)
{
printf("\n\t\tIt Is Positive.");
}
else
{
printf("\n\t\tIt Is Negative.");
}
return 0;
}
Write a C program to accept any number and check
whether it is positive or negative Using Ternary Operator
# include <stdio.h>
int main()
{
int no;
printf("Enter
Any Number:");
scanf("%d",&no);
no>=0 ?
printf("\n\t\tIt Is Positive.") : printf("\n\t\tIt Is
Negative.");
return 0;
}
Write a program to read any number and determine
whether a number is "ODD" or "EVEN" and print the message
NUMBER IS ODD or NUMBER IS EVEN. Using if...else
# include <stdio.h>
int main()
{
int no;
printf("Enter
Any Number:");
scanf("%d",&no);
if(no%2==0)
{
printf("\n\t\tIt Is Even Number.");
}
else
{
printf("\n\t\tIt Is Odd Number.");
}
return 0;
}
Write a program to read any number and determine
whether a number is "ODD" or "EVEN" and print the message
NUMBER IS ODD or NUMBER IS EVEN Using Multiple if
# include <stdio.h>
int main()
{
int no;
printf("Enter
Any Number:");
scanf("%d",&no);
if(no%2==0)
{
printf("\n\t\tIt Is Even Number.");
}
if(no%2!=0)
{
printf("\n\t\tIt Is Odd Number.");
}
return 0;
}
Write a program to read any number and determine
whether a number is "ODD" or "EVEN" and print the message
NUMBER IS ODD or NUMBER IS EVEN Using Ternary Operator
# include <stdio.h>
int main()
{
int no;
printf("Enter
Any Number:");
scanf("%d",&no);
no%2==0 ?
printf("\n\t\tIt Is Even Number.") : printf("\n\t\tIt Is Odd
Number.");
return 0;
}
Write a C program to accept any year in four digits
and check whether it is Leap Year or Not Using if..else
# include <stdio.h>
int main()
{
int year;
printf("Enter
Any Year In Four Digit:");
scanf("%d",&year);
if(year%4==0)
{
printf("\n\t\tIt Is Leap
Year.");
}
else
{
printf("\n\t\tIt Is Not Leap Year.");
}
return 0;
}
Write a C program to accept any year in four digits
and check whether it is Leap Year or Not Using Multiple if
# include <stdio.h>
int main()
{
int year;
printf("Enter
Any Year In Four Digit:");
scanf("%d",&year);
if(year%4==0)
{
printf("\n\t\tIt Is Leap Year.");
}
if(year%4!=0)
{
printf("\n\t\tIt Is Not Leap Year.");
}
return 0;
}
Write a C program to accept any year in four digits
and check whether it is Leap Year or Not Using Ternary Operator
# include <stdio.h>
int main()
{
int year;
printf("Enter
Any Year In Four Digits:");
scanf("%d",&year);
year%4==0 ?
printf("\n\t\tIt Is Leap Year.") : printf("\n\t\tIt Is Not Leap
Year.");
return 0;
}
Write a C program to get two numbers from keyboard and
print the maximum number among them Using if...else
# include <stdio.h>
int main()
{
int a,b;
printf("Enter
Any Two Numbers:");
scanf("%d
%d",&a,&b);
if(a>b)
{
printf("\n\tMax=A");
}
else
{
printf("\n\tMax=B");
}
return 0;
}
Write a C program to get two numbers from keyboard and
print the maximum number among them Using Multiple if
# include <stdio.h>
int main()
{
int a,b;
printf("Enter
Any Two Numbers:");
scanf("%d
%d",&a,&b);
if(a>b)
{
printf("\n\tMax=A");
}
if(b>a)
{
printf("\n\tMax=B");
}
return 0;
}
Write a C program to get two numbers from keyboard and
print the maximum number among them Using Ternary Operator
# include <stdio.h>
int main()
{
int a,b,max;
printf("Enter
Any Two Numbers:");
scanf("%d
%d",&a,&b);
max=a>b? a:b;
printf("\n\tMax=%d",max);
return 0;
}
Write a C program that will read three numeric values
from the user and find out and display the larger one Using Multiple if
# include <stdio.h>
int main()
{
int a,b,c,max;
printf("Enter
Any Three Numbers:");
scanf("%d %d
%d",&a,&b,&c);
if(a>b
&& a>c)
{
printf("\n\tMax=A");
}
if(b>c
&& b>a)
{
printf("\n\tMax=B");
}
if(c>a
&& c>b)
{
printf("\n\tMax=C");
}
return 0;
}
Write a C program that will read three numeric values
from the user and find out and display the larger one Using Nested Ternary
# include <stdio.h>
int main()
{
int a,b,c,max;
printf("Enter
Any Three Numbers:");
scanf("%d %d
%d",&a,&b,&c);
a>b ? a>c ?
printf("\nMax=%d",a)
:
printf("\nMax=%d",c)
: b>c ?
printf("\nMax=%d",b)
:
printf("\nMax=%d",c);
return 0;
}
Write a C program to accept and day number between 1
to 7 and print the messageas Monday if day number is 1,Tuesday if the day
number is 2, Wednesday if day number is 3 and so on. Also display appropriate
message if the day nubmer is less than 1 or greater than 7 Using Multiple if
# include <stdio.h>
int main()
{
int day;
printf("Enter
Day No.:");
scanf("%d",&day);
if(day==1)
{
printf("\n\tMonday");
}
if(day==2)
{
printf("\n\tTuesday");
}
if(day==3)
{
printf("\n\tWednesday");
}
if(day==4)
{
printf("\n\tThursday");
}
if(day==5)
{
printf("\n\tFriday");
}
if(day==6)
{
printf("\n\tSaturday");
}
if(day==7)
{
printf("\n\tSunday");
}
return 0;
}
Write a C program to accept and day number between 1
to 7 and print the messages Monday if day number is 1,Tuesday if the day number
is 2, Wednesday if day number is 3 and so on. Also display appropriate message
if the day nubmer is less than 1 or greater than 7 Using if...else if...else
# include <stdio.h>
int main(){
int day;
printf("Enter
Day Number:");
scanf("%d",&day);
if(day>1)
{
printf("\n\tMonday");
}
else if(day>2)
{
printf("\n\tTuesday");
}
else if(day>3)
{
printf("\n\tWednesday");
}
else if(day>4)
{
printf("\n\tThursday");
}
else if(day>5)
{
printf("\n\tFriday");
}
else if(day>6)
{
printf("\n\tSaturday");
}
else if(day>7)
{
printf("\n\tSunday");
}
else
{
printf("\n\tInvalid Day Number.");
}
return 0;
}
Write a C program to accept and day number between 1
to 7 and print the messages Monday if day number is 1,Tuesday if the day number
is 2, Wednesday if day number is 3 and so on. Also display appropriate message
if the day number is less than 1 or greater than 7 Using switch
# include <stdio.h>
int main()
{
int day;
printf("Enter Day Number Between 1 To
7:");
scanf("%d",&day);
switch(day)
{
case 1:
printf("\n\tMonday.");
break;
case 2:
printf("\n\tTuesday.");
break;
case 3:
printf("\n\tWednesday.");
break;
case 4:
printf("\n\tThursday.");
break;
case 5:
printf("\n\tFriday.");
break;
case 6:
printf("\n\tSaturday.");
break;
case 7:
printf("\n\tSunday.");
break;
default:
printf("\n\tInvalid Day Number.");
break;
}
return 0;
}
Write a C program to accept two numbers and any
arithmetic operator. According to arithmetic operator calculate the result and
display it Using Multiple if
# include <stdio.h>
int main()
{
int a,b;
char op;
printf("Enter
Any Value For A:");
scanf("%d",&a);
printf("Enter
Any Value For B:");
scanf("%d",&b);
printf("Enter
Arithmetic Operator:");
fflush(stdin);
scanf("%c",&op);
if(op=='+')
{
printf("\n\tAddition=%d",a+b);
}
if(op=='-')
{
printf("\n\tSubstraction=%d",a-b);
}
if(op=='*')
{
printf("\n\tMultiplication=%d",a*b);
}
if(op=='/')
{
printf("\n\tDivision=%d",a/b);
}
if(op=='%')
{
printf("\n\tModulus=%d",a%b);
}
return 0;
}
Write a C program to accept two numbers and any
arithmetic operator. According to arithmetic operator calculate the result and display
it Using if...else if...else
# include <stdio.h>
int main()
{
int a,b;
char op;
printf("Enter
Any Value For A:");
scanf("%d",&a);
printf("Enter
Any Value For B:");
scanf("%d",&b);
printf("Enter
Arithmetic Operator:");
fflush(stdin);
scanf("%c",&op);
if(op=='+')
{
printf("\n\tAddition=%d",a+b);
}
else if(op=='-')
{
printf("\n\tSubstraction=%d",a-b);
}
else if(op=='*')
{
printf("\n\tMultiplicatio=%d",a*b);
}
else if(op=='/')
{
printf("\n\tDivision=%d",a/b);
}
else if(op=='%')
{
printf("\n\tModulus=%d",a%b);
}
else
{
printf("\n\tInvalid Arithmetic Operator");
}
return 0;
}
Write a C program to accept two numbers and any
arithmetic operator. According to arithmetic operator calculate the result and
display it Using switch
# include <stdio.h>
int main()
{
int a,b;
char op;
printf("Enter
Value for A:");
scanf("%d",&a);
printf("Enter
Value for B:");
scanf("%d",&b);
printf("Enter
Arilthmetic Operators:");
fflush(stdin) ;
scanf("%c",&op);
switch(op)
{
case '+':
printf("\n\tAddition=%d",a+b);
break;
case '-':
printf("\n\tSubstractio=%d",a-b);
break;
case '*':
printf("\n\tMultiplication=%d",a*b);
break;
case '/':
printf("\n\tDivision=%d",a/b);
break;
case '%':
printf("\n\tModulus=%d",a%b);
break;
default:
printf("\n\tInvalid Arithmetic Operator");
break;
}
return 0;
}
Write a program to get an alphabet from the user and
display message UPPERCASE if it is uppercase alphabet or LOWERCASE if it is
lowercase alphabet.
# include <stdio.h>
int main()
{
char ch;
printf("Enter
Any Character:");
scanf("%c",&ch);
if(ch>='A'
&& ch<='Z')
{
printf("\n\tIt Is Uppercase");
}
else if(ch>='a'
&& ch<='z')
{
printf("\n\tIt Is Lowercase");
}
else
{
printf("\n\tIt Is Not Alphabet");
}
return 0;
}
Write a program that reads a character from keyboard
and then prints it in reverse case.
# include <stdio.h>
int main()
{
int a,b,c;
printf("Enter
Any Value For A:");
scanf("%d",&a);
printf("Enter
Any Value For B:");
scanf("%d",&b);
if(c=a+b)
{
printf("\n\tA=%d",a=c-a);
}
if(b=c-a)
{
printf("\n\tB=%d",b=c-a);
}
return 0;
}
Write a program to get the one character from user and
find out this character is Vowel or Not.
# include <stdio.h>
int main()
{
char ch;
printf("Enter
Any Character:");
scanf("%c",&ch);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||
ch=='I'||ch=='O'||ch=='U')
{
printf("\n\t\tIt Is Vowel");
}
else
if((ch>='a' && ch<='z') || (ch>='A' && ch<='z'))
{
printf("\n\t\tIt Is Not Vowel");
}
else
{
printf("\n\t\tIt Is Not Alphabet");
}
return 0;
}
Enter a character and display a message on the screen
telling the user whether the character is an alphabet or digit, or any other
special character.
# include <stdio.h>
int main()
{
char ch;
printf("Enter
Any Character:");
scanf("%c",&ch);
if((ch>='a'
&& ch<='z')||(ch>='A' && ch<='Z'))
{
printf("\n\tAlphabet");
}
else if(ch>='0'
&& ch<='9')
{
printf("\n\tNumber");
}
else
{
printf("\n\tIt Is Other Character");
}
return 0;
}
Write a C program to calculate and print the final
grade from the marks obtained in 5 different subjects. (Each of having 100
marks,equal weightage)
/*
Percentage
Obtain(Average Marks) Equivalent
Final Grade
==========
============== ====== ========== ===== =====
70 or Above 'O'
Less than 70 but
More or Equal to 60 'A'
Less than 60 but
More or Equal to 50 'B'
Less than 50 but
More or Equal to 40 'C'
Less than
40 'F'
*/
# include <stdio.h>
int main()
{
int
s1,s2,s3,s4,s5,total;
float per;
printf("Enter
Mark of Subject 1 : ");
scanf("%d",&s1);
printf("Enter
Mark of Subject 2 : ");
scanf("%d",&s2);
printf("Enter
Mark of Subject 3 : ");
scanf("%d",&s3);
printf("Enter
Mark of Subject 4 : ");
scanf("%d",&s4);
printf("Enter
Mark of Subject 5 : ");
scanf("%d",&s5);
total=s1+s2+s3+s4+s5;
printf("\n\tTotal=%d",total);
per=total/5;
printf("\n\tPercentage=%.2f",per);
if(per>=70)
{
printf("\n\tGrade O");
}
else
if(per>=60)
{
printf("\n\tGrade A");
}
else
if(per>=50)
{
printf("\n\tGrade B");
}
else
if(per>=40)
{
printf("\n\tGrade
C");
}
else
{
printf("\n\tGrade F");
}
return 0;
}
An electronic power distribution company charges its
domestic consumer as follow.
/*
CONSUMPTION
UNIT RATE OF CHARGE
===========
==== ==== == ======
0 -
200 Rs. 0.40 per unit
201 -
400 Rs. 0.60 per unit
+ Rs. 100
401 -
600 Rs. 0.80 per unit
+ Rs. 250
601 &
above Rs. 1.00 per unit
+ Rs. 400
*/
# include <stdio.h>
int main()
{
int unite;
printf("\n\tEnter Unit:");
scanf("%d",&unite);
if(unite<=200)
{
printf("\n\tRupees=%d",unite/100*40);
}
else
if(unite<=400)
{
printf("\n\tRupees=%d",(unite/100)*(60)+100);
}
else
if(unite<=600)
{
printf("\n\tRupees=%d",(unite/100)*(80)+250);
}
else
{
printf("\n\tRupees=%d",(unite)*(1)+400);
}
return 0;
}
Write a C program to print 1 to n even number.
# include <stdio.h>
int main()
{
int a=2,n;
printf("Enter
Any Number:");
scanf("%d",&n);
while(a<=n)
{
printf("\t%d",a);
a+=2;
}
return 0;
}
Write a C program to print n to 1 odd number.
# include <stdio.h>
int main()
{
int a,n;
printf("Enter
Any Number:");
scanf("%d",&n);
if(n%1==0)
{
a=n-1;
}
else
{
a=n;
}
while(a>=1)
{
printf("\t%d",a);
a=a-2;
}
return 0;
}
Write a C program to print n to 1 even number.
# include <stdio.h>
int main()
{
int a,n;
printf("Enter
Any Number:");
scanf("%d",&n);
if(n%2==1)
{
a=n-1;
}
else
{
a=n;
}
while(a>=1)
{
printf("\t%d",a);
a=a-2;
}
return 0;
}
1,4,9,16,25,36.....n.
#include<stdio.h>
int main()
{
int a,b,c,n;
printf("\n\tEnter value for N=");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
b=a*a;
printf("%d,",b);
}
return 0;
}
1+4+9+16+25+36
#include<stdio.h>
int main()
{
int a,b,c,n,sum=0;
printf("\n\tEnter value for N=");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
b=a*a;
printf("%d,",b);
sum=sum+(a*a);
}
printf("\n\tTotal=%d",sum);
return 0;
}
1,2,4,7,11,16,....n
#include<stdio.h>
int main()
{
int
num,first=1,sec=0,i;
printf("\n\tEnter value for N=");
scanf("%d",&num);
for(i=0;i<num;i++)
{
first=first+sec;
printf("%d\t",first);
sec++;
}
return 0;
}
Write a C program to Generate a Series like 1 11 20 28
35 41 46 50 53 55 56.
# include <stdio.h>
int main()
{
int a,b=10,n;
printf("Enter
Number:");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
printf("%d ",a);
for(b=10;b>=1;b--)
{
a=a+b;
printf("%d ",a);
}
}
return 0;
}
Write a C program to Generate a Series like 1 10 2 9 3
8 4 7 5 6
# include <stdio.h>
int main()
{
int a,b;
for(a=1,b=10;a<=5;a++,b--)
{
printf("\t%d,\t%d,",a,b);
}
return 0;
}
Write a C program to Generate Series like 2 5 10 17
26............n.
# include <stdio.h>
int main()
{
int a,n;
printf("Enter
Any Number:");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
printf("%d ",a*a+1);
}
return 0;
}
write a c program to calculate the series like
1-2+3-4+5-6+7-8+9-10 (Result=-5)
#include<stdio.h>
int main()
{
int
odd=0,even=0,a,n;
printf("\n\tEnterValue for n=");
scanf("%d",&n);
for(a=1;a<=10;a++)
{
if(a%2==0)
{
even=even+a;
}
else
{
odd=odd+a;
}
}
printf("\n\tResult=%d",odd-even);
return 0;
}
Write a C Program to Calculate a Series like 1/1! +
2/2! +. …. + 10/10!
# include <stdio.h>
int main()
{
int
num=1,count,limit;
float sum = 0,
factorial=1;
printf("Series like 1/1!+2/2!+....n/n!\n");
printf("Enter
Stop Number:");
scanf("%d",&limit);
while(num<limit)
{
for(count=1;count<=num;count++)
{
factorial
= factorial * count;
}
sum = sum +
(num / factorial);
num++;
}
printf("Sum
Of The Series: %f",sum);
return 0;
}
Write a C program following series. 2 3 5 9 17 33 65
…….n
# include <stdio.h>
int main()
{
int a,b=1,c=1,d;
printf("Enter
Stop Number :");
scanf("%d",&d);
for(a=1;a<=c;a++)
{
printf("%d ",c);
c=c+b;
b=b*2;
}
return 0;
}
Write a C program to print first 10 numbers of
fibonacci series, which are prime numbers.
# include <stdio.h>
int main()
{
int a,b,limit;
for(a=1,b=10;a<=5;a++,b--)
{
printf("%d %d ",a,b);
}
printf("\n\n");
for(a=2;b<=6;a++)
{
for(b=2;b<=a;b++)
{
if(a%b==0)
{
break;
}
}
if(a==b)
{
printf("%d is Prime Number\n",a);
}
}
return 0;
}
Write a C Program to Calculate and print the sum of
prime numbers between 1 to 25. (Result = 101)
# include <stdio.h>
int main()
{
int
a,b=1,count,sum=0;
printf("Prime
Number between 1 to 25\n");
for(b=1;b<=25;b++)
{
count=0;
for(a=2;a<=b/2;a++)
{
if(b%a==0)
{
count++;
break;
}
}
if(count==0)
{
printf("%d ,",b);
sum=sum+b;
}
}
printf("\nSum
: %d",sum);
return 0;
}
Write a C Program to Calculate the sum of first 50 odd
numbers. ( Result = 625 )
# include <stdio.h>
int main()
{
int a,b=50,sum=0;
for(a=1;a<=b;a++)
{
if(a%2==1)
{
printf("%d ",a);
sum=sum+a;
}
}
printf("\nsum
: %d",sum);
return 0;
}
Write a C Program to Calculate the Series like 1/2 +
2/3 + 3/4 + …+9/10 (Result = 7.071)
# include <stdio.h>
int main()
{
int a,b;
float sum=0;
for(a=1,b=2;a<=9,b<=10;a++,b++)
{
printf("%d/%d+",a,b);
sum=sum+(float)a/b;
}
printf("\nResult : %f",sum);
return 0;
}
Write a program to read any integer number and print
it in reverse.
# include <stdio.h>
int main()
{
long int num, r,
sum = 0, t;
printf("Enter
any number : ");
scanf("%ld",&num);
for(t=num;num!=0;num=num/10)
{
r = num % 10;
sum = sum*10+r;
}
printf("\n\tNumber = %ld",sum);
return 0;
}
Write a program to read any number and print the sum
of all values. For ex. INPUT: 3564 OUTPUT: 3+5+6+4=18
# include <stdio.h>
int main()
{
int no,n,a,sum=0;
printf("Enter
Any Number:");
scanf("%d",&n);
while(n>0)
{
a=n%10;
sum=sum+a;
n=n/10;
}
printf("\n\tSum of all digits is=%d",sum);
return 0;
}
Write a program to determine whether a number is prime
or not. (A prime number is one, which is divisible onlu by 1 or itself only.)
# include <stdio.h>
int main()
{
int num, i = 2;
printf("Enter
any number : ");
scanf("%d",&num);
while(i<num)
{
if(num % i ==
0)
{
printf("\n\tIt is not prime number = %d",num);
break;
}
i++;
}
if(i==num)
printf("\n\tIt is prime number = %d",num);
return 0;
}
Armstrong Number. EX. 153=(1*1*1)+(5*5*5)+(3*3*3)=it
is armstrong number.
# include <stdio.h>
int main()
{
int r,num,t,sum=0;
printf("Enter
Any Number:");
scanf("%d",&num);
t=num;
while(num!=0)
{
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(sum==t)
{
printf("\n\tArmstrong No.=%d",t);
}
else
{
printf("\n\tNot Armstrong No.=%d",t);
}
return 0;
}
Write a program to find out Factorial of a given
number. (e.g. 5! = 120)
# include <stdio.h>
int main()
{
int a,no,fact=1;
printf("Enter
A Number:");
scanf("%d",&no);
for(a=1;a<=no;a++)
{
fact=fact*a;
}
printf("\n\tFactorial of %d is=%d",no,fact);
return 0;
}
1!+2!+3!+4!+5!.........n
# include <stdio.h>
int main()
{
int
n,sum=0,fact=1,i;
printf("Enter
a number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
sum=sum+fact;
}
printf("\n\nSum of all digit's =%d",sum);
return 0;
}
Write a C Program to generate following series:1/2! +
2/3! + 3/4! + 4/5! + ........... (10th term).
# include <conio.h>
int main()
{
int
num=1,count,limit;
float sum = 0,
fact=1;
printf("Series like 1/2!+2/3!+....n/n!\n");
printf("Enter
Stop Number:");
scanf("%d",&limit);
while(num<limit)
{
for(count=1;count<=num;count++)
{
fact =
fact * count;
}
fact++;
sum = sum +
(num / fact);
num++;
}
printf("Sum
Of The Series: %f",sum);
return 0;
}
Write a C Program to generate the following output
1+2+3+4+5+6+7+8+9+10=55
# include <stdio.h>
int main()
{
int a,b=0;
for(a=1;a<=10;a++)
{
printf("%d+",a);
b=b+a;
}
printf("\nResult : %d",b);
return 0;
}
Write a C Program to generate the following output
/*
1
123
12345
1234567
123456789
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=10;a=a+2)
{
for(b=1;b<=a;b++)
{
printf("%d",b);
}
printf("\n");
}
return 0;
}
Write a C Program to print out all Armstrong numbers
between 1 to 500.
# include <stdio.h>
int main()
{
int
n,sum,i,t,a;
printf("Numbers Are:");
for(i=1;i<=500;i++)
{
t=i;
sum=0;
for(;t!=0;)
{
a=t%10;
sum=sum+(a*a*a);
t=t/10;
}
if(sum==i)
{
printf("%d ",i);
}
}
return 0;
}
Write a program and to accept any integer number and
print the individual number in words. For ex. INPUT :- 546 OUTPUT :- Six Four
Five
# include <stdio.h>
int main()
{
int a=0, n;
printf("Enter
any number : ");
scanf("%d",&n);
while(n > 0)
{
a = n % 10;
switch(a)
{
case 0 :
printf("Zero ");
break;
case 1 :
printf("One ");
break;
case 2 :
printf("Two ");
break;
case 3 :
printf("Three ");
break;
case 4 :
printf("Four ");
break;
case 5 :
printf("Five ");
break;
case 6 :
printf("Six ");
break;
case 7 :
printf("Seven ");
break;
case 8 :
printf("Eight ");
break;
case 9 :
printf("Nine ");
break;
}
n=n/10;
}
return 0;
}
Write a program to accept any integer number and print
the individual number in words. For ex. INPUT : 1234 OUTPUT : One Two Three
Four
# include <stdio.h>
int main()
{
long int n,num=0;
printf("Enter
any number:");
scanf("%ld",&n);
while(n!=0)
{
num=(num*10) +
(n%10);
n/=10;
}
while(num != 0)
{
switch(num %
10)
{
case 0:
printf("Zero ");
break;
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Three ");
break;
case 4:
printf("Four ");
break;
case 5:
printf("Five ");
break;
case 6:
printf("Six ");
break;
case 7:
printf("Seven ");
break;
case 8:
printf("Eight ");
break;
case 9:
printf("Nine ");
break;
}
num=num / 10;
}
return 0;
}
Write a C program that accept an integer number and
determine whether the inputted number is palindrome or not?
# include <stdio.h>
int main()
{
char arr[20];
int a,b;
printf("Enter
String:");
gets(arr);
a=0;
while(arr[a] !=
NULL)
{
a++;
}
a--;
b=0;
while(a>=0)
{
if(arr[a] !=
arr[b])
{
printf("\n\t # NOT PALINDROM");
break;
}
a--;
b++;
}
if(a == -1)
{
printf("\n\t # PALINDROM");
}
return 0;
}
Write a C program to do the addition of the first n
terms of the fibonacci series
# include <stdio.h>
int main()
{
int
a,n,t1=0,t2=1,t3,sum=0;
printf("Enter
Number:");
scanf("%d",&n);
//
printf("%d %d ",t1,t2)
for(a=2;a<=n;++a)
{
t3=t1+t2;
printf("%d ",t3);
t1=t2;
t2=t3;
sum=sum+t3;
}
printf("\n\tTotal
Of Series: %d",sum);
return 0;
}
Write a program to find first N prime number.
# include <stdio.h>
int main()
{
long int
num,j,p=2,i;
printf("Enter
a number:");
scanf("%ld",&num);
while(num)
{
for(i=2;i<p;i++)
{
if(p%i==0)
break;
}
if(i==p)
{
printf("%ld ",p);
num--;
}
p++;
}
return 0;
}
Generate following series. 2 3 5 9 17 33 65 …….n
# include <stdio.h>
int main()
{
int a,b=1,c=1,d;
printf("Enter
Stop Number :");
scanf("%d",&d);
for(a=1;a<=c;a++)
{
printf("%d ",c);
c=c+b;
b=b*2;
}
return 0;
}
Display the following series : 1 2 2 4 8 32 256……..up
to a given range
# include <conio.h>
int main()
{
long int
a,n,t1=1,t2=2,t3;
printf("Enter
Number:");
scanf("%ld",&n);
printf("Series like : 1 2 ");
for(a=1;a<=n;a++)
{
t3 = t1 * t2;
printf("%ld ",t3);
t2=t3;
t1=t2;
}
return 0;
}
Write a program to take an integer and find the sum of
first and last digit. Ex. INPUT: 1234 OUTPUT: 5
# include <stdio.h>
int main()
{
long int
n,sum=0,fd,ld;
printf("Enter Any Number:");
scanf("%ld",&n);
ld=n%10;
while(n >= 10)
{
n=n/10;
}
fd=n
sum=fd+ld;
printf("\n\tSum of first and last digits is = %ld",sum);
return 0;
}
Write a C program to do the addition of the first n
terms of the fibonacci series.
# include <stdio.h>
int main()
{
int
a,n,t1=0,t2=1,t3,sum=0;
printf("Enter
Number:");
scanf("%d",&n);
//
printf("%d %d ",t1,t2);
for(a=2;a<=n;++a)
{
t3=t1+t2;
printf("%d ",t3);
t1=t2;
t2=t3;
sum=sum+t3;
}
printf("\n\tTotal
Of Series: %d",sum);
return 0;
}
Write a c program ro find first N prime number.
# include <stdio.h>
int main()
{
int num,j,p=2,i;
printf("Enter
a number:");
scanf("%d",&num);
while(num)
{
for(i=2;i<p;i++)
{
if(p%i==0)
break;
}
if(i==p)
{
printf("%d ",p);
num--;
}
p++;
}
return 0;
}
Write a program, which will read an integer value for
a base, then read a positive integer raised to that base and print its value.
# include <stdio.h>
# include <math.h>
int main()
{
int a,b,c;
printf("\n\tEnter A :");
scanf("%d",&a);
printf("\n\tEnter B :");
scanf("%d",&b);
c = pow(a,b);
printf("\n\t%d^%d = %d",a,b,c);
return 0;
}
Write a C program to input any number and count the
no. of digits in that number.
# include <stdio.h>
int main()
{
long int num,count=0;
printf("Enter
a number:");
scanf("%ld",&num);
while(num)
{
num=num/10;
count++;
}
printf("Total
digit is=%ld",count);
return 0;
}
Write a program to print first 10 numbers of fibonacci
series, which are prime numbers.
# include <stdio.h>
int main()
{
int a,b,limit;
for(a=1,b=10;a<=5;a++,b--)
{
printf("%d %d ",a,b);
}
printf("\n\n");
for(a=2;b<=6;a++)
{
for(b=2;b<=a;b++)
{
if(a%b==0)
{
break;
}
}
if(a==b)
{
printf("%d is Prime Number\n",a);
}
}
return 0;
}
PATTERN
PRINTING
Program to print half pyramid using Numbers.
/*
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
*/
# include <stdio.h>
int main()
{
int a,
b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++){
printf("%d
",b);
}
printf("\n");
}
return
0;
}
Program to print half pyramid using Numbers.
/*
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5;b>=a;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Numbers.
/*
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
*/
# include <stdio.h>
int main()
{
int
a,b;
for(a=1;a<=5;a++){
for(b=a;b>=1;b--){
printf("%d
",b);
}
printf("\n");
}
return
0;
}
Program to print half pyramid using Alphabets.
/*
a
a b
a b c
a b c d
a b c d e
*/
# include <stdio.h>
int main()
{
int
a,b;
for(a=97;a<=101;a++){
for(b=97;b<=a;b++){
printf("%c
",b);
}
printf("\n");
}
return
0;
}
Program to print half pyramid using Numbers.
/*
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=0;b<a;b++){
printf("%d ",a);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Numbers.
/*
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5;b>=a;b--){
printf("%d ",a);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Alphabets.
/*
a
b b
c c c
d d d d
e e e e e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++)
{
for(b=97;b<=a;b++)
{
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Alphabets.
/*
e
d d
c c c
b b b b
a a a a a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=101;b>=a;b--){
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Alphabets.
/*
A
B B
C C C
D D D D
E E E E E
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++)
{
for(b=65;b<=a;b++)
{
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Alphabets.
/*
E
D D
C C C
B B B B
A A A A A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--)
{
for(b=69;b>=a;b--)
{
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Program to print Floyd's Triangle.
/*
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
*/
# include <stdio.h>
int main()
{
int
a,b,c=1;
for(a=1;a<=5;a++){
for(b=1;b<=a;b++){
printf("%d ",c++);
}
printf("\n");
}
return
0;
}
Program to print half pyramid using Zero and one.
/*
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=0;b<a;b++){
printf("%d ",(a+b)%2);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Zero and One.
/*
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<=a;b++){
printf("%d ",(a+b)%2);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Zero and One.
/*
1
0 0
1 1 1
0 0 0 0
1 1 1 1 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<=a;b++){
printf("%d ",a%2);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Zero and One.
/*
0
1 1
0 0 0
1 1 1 1
0 0 0 0 0
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=0;a<5;a++){
for(b=0;b<=a;b++){
printf("%d ",a%2);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Numbers.
/*
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--)
{
for(b=5;b>=a;b--)
{
printf("%d ",a);
}
printf("\n");
}
return 0;
}
Program to print half pyramid using Numbers.
/*
1
1 2
2 3 4
4 5 6 7
7 8 9 10 11
*/
# include <stdio.h>
int main()
{
int a,b,c=1;
for(a=1;a<=5;a++){
printf("\n\t");
for(b=c;b<c+a;b++){
printf("%d ",b);
delay(300);
}
c=b-1;
}
return 0;
}
Inverted half pyramid using numbers
/*
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using numbers
/*
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using numbers
/*
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=a;b<=5;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using numbers
/*
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using zero and one
/*
1 0 1 0 1
0 1 0 1
1 0 1
0 1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=0;b<a;b++){
printf("%d ",(a+b)%2);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using numbers
/*
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=a;b<=5;b++){
printf("%d ",a);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
a b c d e
a b c d
a b c
a b
a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=97;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
a b c d e
b c d e
c d e
d e
e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=a;b<=101;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
A B C D E
A B C D
A B C
A B
A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--){
for(b=65;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
A B C D E
B C D E
C D E
D E
E
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++){
for(b=a;b<=69;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
a a a a a
b b b b
c c c
d d
e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=a;b<=101;b++){
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
A A A A A
B B B B
C C C
D D
E
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++){
for(b=a;b<=69;b++){
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
e e e e e
d d d d
c c c
b b
a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=a;b>=97;b--){
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Alphabets
/*
E E E E E
D D D D
C C C
B B
A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--){
for(b=a;b>=65;b--){
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Zero and One
/*
1 0 1 0 1
0 1 0 1
1 0 1
0 1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=0;b<a;b++){
printf("%d ",(a+b)%2);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Zero and One.
/*
1 1 1 1 1
0 0 0 0
1 1 1
0 0
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf("%d ",a%2);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Zero and One.
/*
0 0 0 0 0
1 1 1 1
0 0 0
1 1
0
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=0;a<=5;a++){
for(b=5;b>a;b--){
printf("%d ",a%2);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Zero and One.
/*
0 1 0 1 0
1 0 1 0
0 1 0
1 0
0
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf("%d ",(a+b)%2);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using Numbers.
/*
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=a;b>=1;b--){
printf("%d ",a);
}
printf("\n");
}
return 0;
}
Inverted half pyramid using numbers
/*
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1
2 1
3
2 1
4 3 2 1
5 4 3 2 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf(" ");
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program.
/*
1
1 2
1 2
3
1 2 3
4
1 2 3 4 5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
5
5 4
5 4
3
5 4 3
2
5 4 3 2 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=1;b<a;b++){
printf(" ");
}
for(b=5;b>=a;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf(" ");
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
5
4 5
3 4
5
2 3 4
5
1 2 3 4 5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=1;b<=a;b++){
printf(" ");
}
for(b=a;b<=5;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1
1 0
1 0
1
1 0 1 0
1 0 1 0 1
*/
# include <stdio.h>
int main()
{
int a,b,c;
for(a=1;a<=5;a++){
for(b=a;b<=5;b++){
printf(". ");
}
for(c=1;c<=a;c++){
printf("%d ",c%2);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
0
0 1
0 1 0
0 1 0
1
0 1 0 1 0
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=1;b<=a;b++){
printf(" ");
}
for(b=a;b<=5;b++){
printf("%d ",(a+b)%2);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A
A B
A
B C
A B C D
A B C D E
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++){
for(b=69;b>a;b--){
printf(" ");
}
for(b=65;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
returnn 0;
}
Pattern Program
/*
a
a b
a b c
a b c d
a b c d e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=101;b>a;b--){
printf(" ");
}
for(b=97;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A
B B
C C
C
D D D D
E E E E E
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=0;a<=4;a++){
for(b=4-1;b>=a;b--){
printf(" ");
}
for(b=0;b<=a;b++){
printf("%c ",a+65);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
e
d d
c c
c
b b b b
a a a a a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=a;b>97;b--){
printf(" ");
}
for(b=a;b<=101;b++){
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
E
D D
C C C
B B B
B
A A A A A
*/
# include
<stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--){
for(b=a;b>65;b--){
printf(" ");
}
for(b=a;b<=69;b++){
printf("%c ",a);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1
0 0
1 1
1
0 0 0
0
1 1 1 1 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("%d ",a%2);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1 2 3 4 5
1 2 3
4
1 2
3
1 2
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5-1;b>=a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
5 4 3 2 1
5 4 3
2
5 4
3
5 4
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<=a;b++){
printf(" ");
}
for(b=5;b>=a;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1 2 3 4 5
2 3 4
5
3 4
5
4 5
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<a;b++){
printf(" ");
}
for(b=a;b<=5;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
5 4 3 2 1
4 3 2
1
3 2 1
2 1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5;b>a;b--){
printf(" ");
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
5 5 5 5 5
4 4 4
4
3 3
3
2 2
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5-1;b>=a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("%d ",a);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1 1 1 1 1
2 2 2
2
3 3
3
4 4
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<=a;b++){
printf(" ");
}
for(b=5;b>=a;b--){
printf("%d ",a);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1 0 1 0 1
0 1 0 1
1 0 1
0 1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5;b>=a;b--){
printf(" ");
}
for(b=0;b<a;b++){
printf("%d ",(a+b)%2);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
0 0 0 0 0
1 1 1
1
0 0
0
1 1
0
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=0;a<=5;a++){
for(b=0;b<a;b++){
printf(" ");
}
for(b=a;b<5;b++){
printf("%d ",a%2);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
a b c d e
a b c
d
a b c
a b
a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=101-1;b>=a;b--){
printf(" ");
}
for(b=97;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A B C D E
A B C
D
A B
C
A B
A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--){
for(b=69-1;b>=a;b--){
printf(" ");
}
for(b=65;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
a b c d e
b c d
e
c d
e
d e
e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=97;b<a;b++){
printf(" ");
}
for(b=a;b<=101;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A B C D E
B C D E
C D E
D E
E
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++){
for(b=65;b<a;b++){
printf(" ");
}
for(b=a;b<=69;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Program to print pyramid using numbers
/*
1
1
2
1
2 3
1 2 3 4
1 2 3 4 5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Program to print pyramid using alphabets
/*
a
a b
a b c
a b c d
a b c d e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=101;b>a;b--){
printf(" ");
}
for(b=97;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program using Star
/*
*
* *
* * *
* * * *
* * * * *
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<=a;b++){
printf("* ");
}
printf("\n");
}
return 0;
}
Program to print full pyramid using star
/*
*
* *
* * *
* * * *
* * * * *
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("* ");
}
printf("\n");
}
return 0;
}
Program to print full pyramid using alphabet
/*
A
A B
A B C
A B C D
A B C D E
*/
# include
<stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++){
for(b=69;b>a;b--){
printf(" ");
}
for(b=65;b<=a;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Program to print full pyramid using alphabet
/*
e
e d
e d c
e d c b
e d c b a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=97;b<a;b++){
printf(" ");
}
for(b=101;b>=a;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Program to print full pyramid using numbers
/*
1
1
2 1
1 2
3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2
1
*/
# include
<stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>a;b--){
printf(" ");
}
for(b=1;b<a;b++){
printf("%d ",b);
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Program to print full pyramid using numbers
/*
1
2 1
2
3 2
1 2 3
4 3 2
1 2 3 4
5 4 3 2 1 2 3 4
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>=a;b--){
printf(" ");
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\b\b");
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Program to print pyramid using alphabet
/*
a
a b
a
a b
c b a
a b c
d c b a
a b c d e d c b
a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=101;b>a;b--){
printf(" ");
}
for(b=97;b<a;b++){
printf("%c ",b);
}
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Program to print pyramid using alphabet
/*
A
A B
A
A B
C B A
A B C
D C B A
A B C D E D C B
A
*/
# include
<stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++){
for(b=69;b>=a;b--){
printf(" ");
}
for(b=65;b<a;b++){
printf("%c ",b);
}
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Program to print pyramid using alphabet
/*
e
e d
e
e d
c d e
e d c
b c d e
e d c b a b c d
e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=97;b<a;b++){
printf(" ");
}
for(b=101;b>a;b--){
printf("%c ",b);
}
for(b=a;b<=101;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Program to print pyramid using alphabet
/*
E
D E D
C D E
D C
B C D E
D C B
A B C D E D C B
A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--){
for(b=65;b<a;b++){
printf(" ");
}
for(b=a;b<=69;b++){
printf("%c ",b);
}
printf("\b\b");
for(b=69;b>=a;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Program to print pyramid using numbers
/*
5
5 4
5
5 4
3 4 5
5 4 3
2 3 4 5
5 4 3 2 1 2 3 4
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=1;b<=a;b++){
printf(" ");
}
for(b=5;b>a;b--){
printf("%d ",b);
}
for(b=a;b<=5;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Inverted full pyramid using numbers
/*
1 2 3 4 5 4 3 2
1
1 2 3
4 3 2 1
1 2
3 2 1
1 2
1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5;b>a;b--){
printf(" ");
}
for(b=1;b<a;b++){
printf("%d ",b);
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Inverted full pyramid using numbers.
/*
1 2 3 4 5 4
3 2 1
2
3 4 5 4 3 2
3 4 5 4 3
4 5 4
5
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<a;b++){
printf(" ");
}
for(b=a;b<=5;b++){
printf("%d ",b);
}
printf("\b\b");
for(b=5;b>=a;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Inverted full pyramid using alphabet
/*
A B C D E D C B A
A B C
D C B A
A B
C B A
A B
A
A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--){
for(b=69;b>a;b--){
printf(" ");
}
for(b=65;b<a;b++){
printf("%c ",b);
}
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Inverted full pyramid using alphabet
/*
a b c d e d c b
a
b c d
e d c b
c d
e d c
d e
d
e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=97;b<a;b++){
printf(" ");
}
for(b=a;b<=101;b++){
printf("%c ",b);
}
printf("\b\b");
for(b=101;b>=a;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A B C D E D
C B A
A B C
D D C B A
A B C C B A
A B B A
A A
*/
# include <stdio.h>
int main()
{
char a,b;
for(a=69;a>=65;a--){
for(b=65;b<=a;b++){
printf("%c ",b);
}
for(b=69;b>a;b--){
printf(" ");
}
printf("\b\b");
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
a b c d e d c b a
a b c d d c b
a
a b c c b a
a b b a
a a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=97;b<=a;b++){
printf("%c ",b);
}
for(b=101;b>a;b--){
printf(" ");
}
printf("\b\b");
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A A
A B B A
A B C C B A
A B C D D C B A
A B C D E D C B A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=65;a<=69;a++){
for(b=65;b<=a;b++){
printf("%c ",b);
}
for(b=69;b>=a;b--){
printf(" ");
}
printf("\b\b\b\b");
for(b=69;b>=a;b--){
printf(" ");
}
printf("\b\b");
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
a a
a b b a
a b c c b a
a b c d d c b
a
a b c d e d c b
a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=97;b<=a;b++){
printf("%c ",b);
}
for(b=101;b>=a;b--){
printf(" ");
}
printf("\b\b\b\b");
for(b=101;b>=a;b--){
printf(" ");
}
printf("\b\b");
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2
1
1 2 3 3 2 1
1 2 2 1
1 1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=1;b<=a;b++){
printf("%d ",b);
}
for(b=5;b>a;b--){
printf(" ");
}
printf("\b\b");
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4
4 3 2 1
1 2 3 4 5 4 3 2
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=1;b<=a;b++){
printf("%d ",b);
}
for(b=5;b>=a;b--){
printf(" ");
}
printf("\b\b\b\b");
for(b=5;b>=a;b--){
printf(" ");
}
printf("\b\b");
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
e d c b a b c d e
e d c b b c d
e
e d c c d e
e d d e
e e
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<=101;a++){
for(b=101;b>=a;b--){
printf("%c ",b);
}
for(b=97;b<a;b++){
printf(" ");
}
printf("\b\b");
for(b=97;b<a;b++){
printf(" ");
}
for(b=a;b<=101;b++){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1
1 2
1
1 2
3 2 1
1 2 3
4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<5;a++){
for(b=5;b>a;b--){
printf(" ");
}
for(b=1;b<a;b++){
printf("%d ",b);
}
for(b=a;b>=1;b--){
printf("%d
",b);
}
printf("\n");
}
for(a=5;a>=1;a--){
for(b=5;b>a;b--){
printf(" ");
}
for(b=1;b<a;b++){
printf("%d ",b);
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1
2
1 2
3 2
1 2 3
4 3 2
1 2 3 4
5 4 3 2 1 2 3 4
5
4 3
2 1 2 3 4
3 2 1 2 3
2 1
2
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=1;a<=5;a++){
for(b=5;b>a;b--){
printf(" ");
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\b\b");
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\n");
}
for(a=4;a>=1;a--){
for(b=4;b>=a;b--){
printf(" ");
}
for(b=a;b>=1;b--){
printf("%d
",b);
}
printf("\b\b");
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
a
a b
a
a b
c b a
a b c
d c b a
a b c d e d c b
a
a b c d c b a
a b c b a
a b a
a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=97;a<101;a++){
for(b=101;b>a;b--){
printf(" ");
}
for(b=97;b<a;b++){
printf("%c ",b);
}
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
for(a=101;a>=97;a--){
for(b=101;b>a;b--){
printf(" ");
}
for(b=97;b<a;b++){
printf("%c ",b);
}
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A
A B A
A B C
B A
A B C D
C B A
A B C D E D C B
A
A B C D C B A
A B C
B A
A B A
A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=65;a<69;a++){
for(b=69;b>a;b--){
printf(" ");
}
for(b=65;b<a;b++){
printf("%c ",b);
}
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
for(a=69;a>=65;a--){
for(b=69;b>a;b--){
printf(" ");
}
for(b=65;b<a;b++){
printf("%c ",b);
}
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
1 2 3 4 5 4 3 2
1
1 2 3
4 3 2 1
1 2
3 2 1
1 2
1
1
1 2 1
1
2 3 2 1
1 2 3 4
3 2 1
1 2 3 4 5 4 3 2
1
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=5;a>=1;a--){
for(b=5-1;b>=a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\b\b");
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
for(a=2;a<=5;a++){
for(b=5-1;b>=a;b--){
printf(" ");
}
for(b=1;b<=a;b++){
printf("%d ",b);
}
printf("\b\b");
for(b=a;b>=1;b--){
printf("%d ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
A B C D E D C B
A
A B C
D C B A
A B
C B A
A B
A
A
A B A
A B C
B A
A B C D C B A
A B C D E D C B
A
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=69;a>=65;a--){
for(b=69-1;b>=a;b--){
printf(" ");
}
for(b=65;b<=a;b++){
printf("%c ",b);
}
printf("\b\b");
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
for(a=66;a<=69;a++){
for(b=69-1;b>=a;b--){
printf(" ");
}
for(b=65;b<=a;b++){
printf("%c ",b);
}
printf("\b\b");
for(b=a;b>=65;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Pattern Program
/*
a b c d e d c b
a
a b c
d c b a
a b
c b a
a b
a
a
a b a
a
b c b a
a b c d
c b a
a b c d e d c b
a
*/
# include <stdio.h>
int main()
{
int a,b;
for(a=101;a>=97;a--){
for(b=101-1;b>=a;b--){
printf(" ");
}
for(b=97;b<=a;b++){
printf("%c ",b);
}
printf("\b\b");
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
for(a=98;a<=101;a++){
for(b=101-1;b>=a;b--){
printf(" ");
}
for(b=97;b<=a;b++){
printf("%c ",b);
}
printf("\b\b");
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
return 0;
}
Complex Pattern Program using numbers with alphabet
/*
1 2 3 4 5 4 3 2
1
1 2 3 4 a 4 3 2
1
1 2 3 a b a 3 2
1
1 2 a b c b a 2
1
1 a b c d c b a
1
1 2 a b c b a 2
1
1 2 3 a b a 3 2
1
1 2 3 4 a 4 3 2
1
1 2 3 4 5 4 3 2
1
*/
# include <stdio.h>
int main()
{
int a,b,c=96,d=2;
for(a=5;a>=1;a--){
for(b=1;b<=a;b++){
printf("%d ",b);
}
if(a==5)
printf("\b\b");
for(b=97;b<c;b++){
printf("%c ",b);
}
for(b=c;b>=97;b--){
printf("%c ",b);
}
for(b=a;b>=1;b--){
printf("%d ",b);
}
c++;
printf("\n");
}
c-=2;
for(a=1;a<=4;a++){
for(b=1;b<=d;b++){
printf("%d ",b);
}
if(a==4)
printf("\b\b");
for(b=97;b<c;b++){
printf("%c ",b);
}
for(b=c;b>=97;b--){
printf("%c ",b);
}
for(b=d;b>=1;b--){
printf("%d ",b);
}
c--;
d++;
printf("\n");
}
return 0;
}
Complex Pattern Program using alphabet with numbers
/*
a b c d e d c b
a
a b c d 1 d c b
a
a b c 1 2 1 c b
a
a b 1 2 3 2 1 b
a
a 1 2 3 4 3 2 1
a
a b 1 2 3 2 1 b
a
a b c 1 2 1 c b
a
a b c d 1 d c b
a
a b c d e d c b
a
*/
# include <stdio.h>
int main()
{
int a, b, c=0,
d=98;
for(a=101;a>=97;a--){
for(b=97;b<=a;b++){
printf("%c ",b);
}
for(b=1;b<=c;b++){
printf("%d ",b);
}
printf("\b\b");
for(b=c;b>=1;b--){
printf("%d ",b);
}
c++;
for(b=a;b>=97;b--){
printf("%c ",b);
}
printf("\n");
}
c-=2;
for(a=97;a<=100;a++){
for(b=97;b<=d;b++){
printf("%c ",b);
}
if(a==100) {
printf("\b\b");
}
for(b=1;b<c;b++){
printf("%d ",b);
}
for(b=c;b>=1;b--){
printf("%d ",b);
}
for(b=d;b>=97;b--){
printf("%c ",b);
}
c--;
d++;
printf("\n");
}
return 0;
}
Pattern Program
/*
1
1 2
2 3 4
3 4 5 6
7 8 9 10 11
*/
# include <stdio.h>
int main()
{
int a, b, c=1;
for(a=1;a<=5;a++){
for(b=c;b<c+a;b++){
printf("%d ",b);
}
printf("\n");
c=b-1;
}
return 0;
}
Pattern Program
/*
H
H K
H K L
H K L K
H K L K H
*/
# include <stdio.h>
int main()
{
int a,b;
for(a='H';a<='L';a++){
for(b='H';b<=a;b++){
if(b=='H')
{
printf("H ");
}
if(b=='I')
{
printf("K ");
}
if(b=='J')
{
printf("L ");
}
if(b=='K')
{
printf("K ");
}
if(b=='L')
{
printf("H ");
}
}
printf("\n");
}
return 0;
}
ARRAY
Get the 10 numbers from users & calculate Total
and Average.
# include
<stdio.h>
int main()
{
int arr[10],a;
float sum =
0.0,avg;
for(a=0;a<10;a++){
printf("Enter Value :");
scanf("%d",&arr[a]);
}
for(a=0;a<10;a++){
sum = sum +
arr[a];
}
avg = sum / 10.0;
printf("\nSum
: %.2f",sum);
printf("\nAverage : %.2f",avg);
return 0;
}
Write a Program to get 10 students marks from user and
sort it in Ascending and Descending order.
# include
<stdio.h>
int main()
{
int
arr[10],a,temp,b;
for(a=0;a<10;a++){
printf("Enter Marks:");
scanf("%d",&arr[a]);
}
printf("\n\tASCENDING");
for(a=0;a<10;a++){
for(b=a+1;b<10;b++){
if( arr[a] > arr[b] ) {
temp =
arr[a];
arr[a]
= arr[b];
arr[b]
= temp;
}
}
printf("\n Marks : %d",arr[a]);
}
printf("\n\tDESCENDING");
for(a=0;a<10;a++){
for(b=a+1;b<10;b++){
if( arr[a]
< arr[b] ) {
temp =
arr[a];
arr[a]
= arr[b];
arr[b]
= temp;
}
}
printf("\n Marks : %d",arr[a]);
}
return 0;
}
Write a Program to sort an array of 10 elements using
bubble sort.
# include <stdio.h>
int main()
{
int
arr[10],temp,a,b;
for(a=0;a<10;a++){
printf("Enter Value :");
scanf("%d",&arr[a]);
}
for(a=0;a<10;a++){
for(b=a+1;b<10;b++){
if(arr[a]
> arr[b]) {
temp =
arr[a];
arr[a]
= arr[b];
arr[b]
= temp;
}
}
printf("\t\n Bubble Sort : %d",arr[a]);
}
return 0;
}
Write a Program that reads n elements in an array;
print all odd values of the list, print all even values of the list and count
how many odd values and how many even values in the list.
# include <stdio.h>
int main()
{
int arr[1000],odd[1000],even[1000],a,b,co,ce,n;
co=ce=0;
printf ("How
many value you want to enter : ");
scanf
("%d",&n);
for(a=0;a<n;a++){
printf("Enter Number : ");
scanf("%d",&arr[a]);
}
for(a=0;a<n;a++){
odd[a]=even[a]=0;
if(arr[a] % 2
== 0) {
even[a] = arr[a];
ce++;
printf("\nEven :
%d",even[a]);
}
else{
odd[a] = arr[a];
co++;
printf("\nOdd : %d",odd[a]);
}
}
printf("\n\nEven Count : %d",ce);
printf("\n\nOdd Count : %d",co);
return 0;
}
Write a Program that reads n elements in an array,
count how many zero, how many positive and how many negative values.
# include
<stdio.h>
int main()
{
int
arr[1000],zero,pve,nve,a, n;
printf("How many number you want to enter : ");
scanf
("%d",&n);
for(a=0;a<n;a++){
printf("Enter Value : ");
scanf("%d",&arr[a]);
}
zero=pve=nve=0;
for(a=0;a<n;a++){
if(arr[a]
> 0) {
pve++;
}
else if
(arr[a] < 0) {
nve++;
}
else{
zero++;
}
}
printf("\nPositive : %d",pve);
printf("\nZero : %d",zero);
printf("\nNegative : %d",nve);
return 0;
}
Write a Program that reads n values in an array; enter
a number and find how many times the number is repeated in the list.
#include
<stdio.h>
int main()
{
int arr[10000], a,
search, count = 0, size;
printf("Enter
Elements For Array : ");
scanf("%d", &size);
for (a = 0; a <
size; a++){
printf("\nEnter
Value %d : ", a + 1);
scanf("%d", &arr[a]);
}
printf("\nEnter Number To Be Searched : ");
scanf("%d", &search);
for (a = 0; a <
size; a++){
if (arr[a] ==
search) {
count++;
}
}
printf("\n
The Number %d Is %d times Reapeted", search, count);
return 0;
}
Single Dimension Array. Write a C program to enter 10
number in array and also enter search number and check the search number is an
array or not.
# include
<stdio.h>
int main()
{
int arr[10], a,
sv;
for(a=0;a<10;a++){
printf("Enter any Number : ");
scanf("%d",&arr[a]);
}
printf("\n\nEnter Search Value : ");
scanf("%d",&sv);
for(a=0;a<10;a++){
if(arr[a] ==
sv) {
printf("\n\tThe Search Value %d is found on position
%d",sv,a+1);
break;
}
}
if(a == 10) {
printf("\n\tSearch Value %d not found");
}
return 0;
}
Write a Cprogram that reads 10 values in an array;
find how many are them are prime numbers; Store all prime numbers in another
array.
# include
<stdio.h>
int main()
{
int arr[10],a,b,count,prime[10],n=0;
for(a=0;a<10;a++){
printf("Enter value:");
scanf("%d",&arr[a]);
}
for(a=0;a<10;a++){
count=0;
for(b=2;b<arr[a];b++){
if(arr[a]
% b == 0) {
count=1;
break;
}
}
if(count==0) {
prime[n]=arr[a];
n++;
}
}
prime[n]=NULL;
for(a=0;a<n;a++){
printf("\nPrime Number : %d",prime[a]);
}
return 0;
}
Single Dimension Array. Write a C program to enter 10
number in array and also enter search number and check the search number is an
array or not
# include
<stdio.h>
int main()
{
int arr[10], a,
sv=0;
for(a=0;a<10;a++){
printf("Enter any Number : ");
scanf("%d",&arr[a]);
}
printf("\n\nEnter Search Value : ");
scanf("%d",&sv);
for(a=0;a<10;a++){
if(arr[a] ==
sv) {
printf("\n\tThe Search Value %d is found on position
%d",sv,a+1);
break;
}
}
if(a == 10){
printf("\n\tSearch
Value %d not found", sv);
}
return 0;
}
Double Dimension Array.
# include
<stdio.h>
int main()
{
int arr[3][4], a,
b;
for(a=0;a<3;a++){
for(b=0;b<4;b++){
printf("Enter any numbers : ");
scanf("%d",&arr[a][b]);
}
}
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<4;b++){
printf("\t%d",arr[a][b]);
}
}
return 0;
}
Double Dimension Array. Addition of two matrix.
# include <stdio.h>
int main()
{
int arr1[3][3],
arr2[3][3], arr3[3][3], a, b;
printf("\n\nEnter 9 Value
for arr1 : ");
for(a=0;a<3;a++){
for(b=0;b<3;b++){
printf("\nEnter any number : ");
scanf("%d",&arr1[a][b]);
}
}
printf("\n\nEnter 9 Value for arr2 : ");
for(a=0;a<3;a++){
for(b=0;b<3;b++){
printf("\nEnter any number : ");
scanf("%d",&arr2[a][b]);
}
}
for(a=0;a<3;a++){
for(b=0;b<3;b++){
arr3[a][b]
= arr1[a][b] + arr2[a][b];
}
}
printf("\n\nMatrix 1 : ");
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<3;b++){
printf("\t%d",arr1[a][b]);
}
}
printf("\n\nMatrix 2 : ");
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<3;b++){
printf("\t%d",arr2[a][b]);
}
}
printf("\n\nAddition of two matrixes : ");
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<3;b++){
printf("\t%d",arr3[a][b]);
}
}
return 0;
}
Double Dimension Array.
Write a
Cprogram to enter values in 3 * 3 matrix and print row total,
column total and grand total.
INPUT :-
1 2 3
4 5 6
7 8 9
OUTPUT :-
1 2
3 6
4 5
6 15
7 8
9 24
12 15
18 45
# include <stdio.h>
int main()
{
int arr[4][4] =
{0}, a, b;
for(a=0;a<3;a++){
for(b=0;b<3;b++){
printf("Enter any number : ");
scanf("%d",&arr[a][b]);
}
}
for(a=0;a<3;a++){
for(b=0;b<3;b++){
arr[a][3] =
arr[a][3] + arr[a][b]; // Row Total
arr[3][a]
= arr[3][a] + arr[b][a]; // Column Total
}
arr[3][3] =
arr[3][3] + arr[3][a]; // Grand Total
}
for(a=0;a<4;a++){
printf("\n\n");
for(b=0;b<4;b++){
printf("\t%d",arr[a][b]);
}
}
return 0;
}
Double Dimension Array. Transpose of a matrix.
Write a C
program to enter values in 3 * 3 matrix and transpose
the entered matrix.
INPUT :-
1 2 3
4
5 6
7 8 9
OUTPUT :-
1 4 7
2 5 8
3 6 9
# include <stdio.h>
int main()
{
int arr[3][3], a,
b;
for(a=0;a<3;a++){
for(b=0;b<3;b++){
printf("Enter any number : ");
scanf("%d",&arr[a][b]);
}
}
printf("\n\nEntered Matrix ");
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<3;b++){
printf("\t%d",arr[a][b]);
}
}
printf("\n\nTranspose
matrix : ");
for(a=0;a<3;a++) {
printf("\n\n");
for(b=0;b<3;b++){
printf("\t%d",arr[b][a]);
}
}
return 0;
}
Write a program that reads values in an 3 * 4 array,
get sum of all the values and print the sum as well as average of all values.
# include <stdio.h>
int main()
{
int arr[3][4], a,
b, sum = 0;
float average;
for(a=0;a<3;a++)
for(b=0;b<4;b++){
printf("Enter any number : ");
scanf("%d",&arr[a][b]);
}
}
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<4;b++){
printf("\t%d",arr[a][b]);
}
}
for(a=0;a<3;a++){
for(b=0;b<4;b++){
sum = sum + arr[a][b];
}
}
average = sum /
10.0;
printf("\n\n\tSum = %d",sum);
printf("\n\tAverage
= %.2f",average);
return 0;
}
Double Dimention Array Write a program thar performs
transpose on a matrix of size 3 * 3; print resultant matrix.
# include
<stdio.h>
int main()
{
int arr[3][3], a,
b;
for(a=0;a<3;a++){
for(b=0;b<3;b++){
printf("Enter anu number : ");
scanf("%d",&arr[a][b]);
}
}
printf("\n\nEnter
Matrix : ");
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<3;b++){
printf("\t%d",arr[a][b]);
}
}
printf("\n\n
Transpose Matrix : ");
for(a=0;a<3;a++){
printf("\n\n");
for(b=0;b<3;b++){
printf("\t%d",arr[b][a]);
}
}
return 0;
}
Double Dimension Array. Write a program that accepts
values in an array of size 3 * 3 and get row total and column total for each
row and each column. print the array and its total in tabular form.
# include <stdio.h>
int main()
{
int arr[4][4] =
{0}, a, b;
for(a=0;a<3;a++){
for(b=0;b<3;b++){
printf("Enter any number : ");
scanf("%d",&arr[a][b]);
}
}
for(a=0;a<3;a++){
for(b=0;b<3;b++){
arr[a][3]
= arr[a][3] + arr[a][b];
arr[3][a]
= arr[3][a] + arr[b][a];
}
arr[3][3] =
arr[3][3] + arr[3][a];
}
for(a=0;a<4;a++){
printf("\n\n");
for(b=0;b<4;b++){
printf("\t%d",arr[a][b]);
}
}
return 0;
}
Multi Dimension Array.
# include
<stdio.h>
int main()
{
int arr[2][2][2],
a, b, c;
for(a=0;a<2;a++){
for(b=0;b<2;b++){
for(c=0;c<2;c++){
printf("Enter any number : ");
scanf("%d",&arr[a][b][c]);
}
}
}
for(a=0;a<2;a++){
printf("\n\n");
for(b=0;b<2;b++){
printf("\n\t");
for(c=0;c<2;c++){
printf("\t%d",arr[a][b][c]);
}
}
}
return 0;
}
Character Array.
# include <stdio.h>
# include <string.h>
int main()
{
char str[10];
strcpy(str,"Welcome");
printf("\n\tString = %s",str);
return 0;
}
Character Array. Accept string and give the length of
string.
# include <stdio.h>
# include <string.h>
int main()
{
char str[40];
int a;
printf("Enter
any String : ");
gets(str);
printf("\n\nString Length = %d",strlen(str));
a = 0;
while(str[a] !=
'\0') // OR while(str[a] != NULL) {
a++;
}
printf("\n\tString Length = %d",a);
return 0;
}
Character Array. Write a C program to enter any string
and print it in reverse. INPUT :- Computer OUTPUT :- retupmoC
# include <stdio.h>
# include <string.h>
int main()
{
char str[80];
int a;
printf("Enter
any String : ");
gets(str);
printf("\n\t\tString Reverse =
%s",strrev(str));
return 0;
}
Character Array. Overflow.
# include
<stdio.h>
int main()
{
char str[10];
printf("Enter
any String : ");
gets(str);
printf("\n\tString = %s",str);
return 0;
}
Character Array. Write a C program to enter any string
and copy it into another string.
# include <stdio.h>
int main()
{
char str1[40],
str2[40];
int a;
printf("Enter
any String : ");
gets(str1);
a = 0;
while(str1[a] !=
'\0') {
str2[a] =
str1[a];
a++;
}
str2[a] = '\0'; //
str2[a] = NULL.
printf("\n\tString
copy = %s",str2);
return 0;
}
Character Array Write a C program to enter any string
and print it in uppercase.
# include <stdio.h>
# include <string.h>
int main()
{
char str[40];
int a;
printf("Enter
any String : ");
gets(str);
printf("uppercase = %s",strupr(str)); // METHOD 2.
a = 0;
while(str[a] !=
NULL) {
if(str[a]
>= 'a' && str[a] <='z') {
str[a] =
str[a] - 32;
}
a++;
}
printf("\n\tUppercase
= %s",str);
return 0;
}
Character Array Write a C program to enter any string
and check the entered string is palindrom or not. INPUT :- nayan OUTPUT :-
palidrom string
# include <stdio.h>
int main()
{
char str[40];
int a, b;
printf("Enter
any string : ");
gets(str);
a = 0;
while(str[a] !=
NULL) {
a++;
}
a--;
b = 0;
while(a >= 0) {
if(str[a] !=
str[b]) {
printf("\n\tNOT Palidrom String");
break;
}
a--;
b++;
}
if(a == -1) {
printf("\n\tPalidrom String");
}
return 0;
}
Write a C program to enter any word and print it as
below:
INPUT :- Computer
OUTPUT :- C
Co
Com
Comp
Compu
Comput
Compute
Computer
# include <stdio.h>
# include <string.h>
int main()
{
char str[20];
int a, b;
printf("Enter any String : ");
gets(str);
for(a=0;a<strlen(str);a++){
for(b=0;b<=a;b++){
printf("%c",str[b]);
}
printf("\n");
}
return 0;
}
accept string and print it into reverse order.
# include <stdio.h>
# include <string.h>
int main()
{
char arr[10];
int a=0;
printf("Enter
A String:");
gets(arr);
printf("\nReverse Strings : %s",strrev(arr));
return 0;
}
accept string and print it into alphabetical reverse
order.
# include <stdio.h>
# include <string.h>
int main()
{
char
str[100],temp;
int a,b;
printf("Enter
String:");
gets(str);
printf("\nIn
Alphabetical Order:");
for(a=0;str[a];a++){
for(b=0;str[b];b++){
if(str[b]<str[a]) {
temp =
str[a];
str[a]
= str[b];
str[b]
= temp;
}
}
}
printf("%s\n",str);
return 0;
}
String array accept string and convert it into
uppercase.
# include <stdio.h>
# include <string.h>
int main()
{
char arr[20],a;
printf("Enter
A String:");
gets(arr);
printf("\n\n
Uppercase String : %s",strupr(arr));
return 0;
}
String array enter string and find the lenght of
string.
# include <stdio.h>
# include <string.h>
int main()
{
char str[40];
int a;
printf("Enter
any String : ");
gets(str);
printf("\n\nString Length = %d",strlen(str));
a = 0;
while(str[a] !=
'\0') // OR while(str[a] != NULL) {
a++;
}
printf("\n\tString Length = %d",a);
return 0;
}
STRUCTURE
Structure. Enter strudent Roll no, marks and name and
print it using structure.
# include <stdio.h>
int main()
{
struct student{
int rollno;
char name[20];
int mark;
};
struct student st;
printf("Enter
Roll No.:");
scanf("%d",&st.rollno);
printf("Enter
Name:");
fflush(stdin);
gets(st.name);
printf("Enter
Marks:");
scanf("%d",&st.mark);
printf("\nRoll No :%d",st.rollno);
printf("\nName : %s",st.name);
printf("\nMarks:%d",st.mark);
return 0;
}
Structure. Enter Emplyee code, name, and salary and
count hra, da, pf, net salary using structure.
# include <stdio.h>
int main()
{
struct employee{
int code;
char name[10];
float basic,
hra, da, pf, net;
}emp;
printf("Enter
emp. code : ");
scanf("%d",&emp.code);
printf("Enter
emp. Name : ");
fflush(stdin);
gets(emp.name);
printf("Enter
Basic Salary : ");
scanf("%f",&emp.basic);
emp.hra =
emp.basic*10/100;
emp.da =
emp.basic*1.5/100;
emp.pf =
emp.basic*5/100;
emp.net =
emp.basic+emp.hra+emp.da+emp.pf;
printf("\n\tEmp.Code = %d",emp.code);
printf("\n\tEmp.Name = %s",emp.name);
printf("\n\tBasic = %.2f",emp.basic);
printf("\n\tHRA = %.2f",emp.hra);
printf("\n\tDA
= %.2f",emp.da);
printf("\n\tPF = %.2f",emp.pf);
printf("\n\tNet Salary = %.2f",emp.net);
return 0;
}
Structure. Array of Structure.
# include
<stdio.h>
int main()
{
struct student{
int rollno;
char name[20];
float percent;
};
struct student
st[5];
int a;
for(a=0;a<5;a++){
printf("Enter Roll no : ");
scanf("%d",&st[a].rollno);
printf("Enter Name : ");
fflush(stdin);
gets(st[a].name);
printf("Enter
Percent : ");
scanf("%f",&st[a].percent);
}
printf("\n\n\t\tRoll no\t\tName\t\tPercentage");
for(a=0;a<5;a++){
printf("\n\t\t%d\t\t%s\t\t%.2f",st[a].rollno,st[a].name,st[a].percent);
}
return 0;
}
float * abc(float * p)
{
return p;
}
Structure. Write a program to calculate the Net
Salary, HRA, DA, Pf of 5 employee with help of structure according to the basic
& following condition and print it.
Net Salary = Basic + HRA + DA - pf.
===============================================
Basic || HRA
|| DA || pf
===============================================
>=
10000 || 20%
|| 15% || 10%
>= 5000 and
< 10000 || 15%
|| 10% || 5%
<5000 || 5%
|| 5% || --
===============================================
# include <stdio.h>
int main()
{
struct emp{
float net,
hra, da, pf, bs;
};
struct emp hp;
printf("Enter
Basic Salary : ");
scanf("%f",&hp.bs);
if(hp.bs <=
5000) {
hp.hra =
(hp.bs * 10) / 100;
hp.da = (hp.bs
* 5) / 100;
hp.pf = 0;
}
if(hp.bs > 5000
&& hp.bs <= 10000) {
hp.hra =
(hp.bs * 15) / 100;
hp.da = (hp.bs
* 10) / 100;
hp.pf = (hp.bs
* 5) / 100;
}
if(hp.bs >
10000) {
hp.hra =
(hp.bs * 20) / 100;
hp.da = (hp.bs
* 15) / 100;
hp.pf = (hp.bs
* 5) / 100;
}
hp.net = hp.bs +
hp.hra + hp.da - hp.pf;
printf("\nBasic Salary = %.2f",hp.bs);
printf("\nHRA
= %.2f",hp.hra);
printf("\nDA
= %.2f",hp.da);
printf("\nPF
= %.2f",hp.pf);
printf("\nNet
Salary = %.2f",hp.net);
return 0;
}
Character Array. Write a C program to enter any string
and copy it into another string.
# include <stdio.h>
int main()
{
char str1[40],
str2[40];
int a;
printf("Enter
any String : ");
gets(str1);
a = 0;
while(str1[a] !=
'\0') {
str2[a] =
str1[a];
a++;
}
str2[a] = '\0'; //
str2[a] = NULL.
printf("\n\tString copy = %s",str2);
return 0;
}
Character Array Write a C program to enter any string
and print it in uppercase.
# include <stdio.h>
# include <string.h>
int main()
{
char str[40];
int a;
printf("Enter
any String : ");
gets(str);
printf("uppercase
= %s",strupr(str)); // METHOD 2.
a = 0;
while(str[a] !=
NULL) {
if(str[a]
>= 'a' && str[a] <='z') {
str[a] =
str[a] - 32;
}
a++;
}
printf("\n\tUppercase = %s",str);
return 0;
}
Structure. Enter strudent Roll no, marks and name and
print it using structure.
# include <stdio.h>
int main()
{
struct student{
int rollno;
char name[20];
int mark;
};
struct student st;
printf("Enter
Roll No.:");
scanf("%d",&st.rollno);
printf("Enter
Name:");
fflush(stdin);
gets(st.name);
printf("Enter
Marks:");
scanf("%d",&st.mark);
printf("\nRoll No :%d",st.rollno);
printf("\nName : %s",st.name);
printf("\nMarks:%d",st.mark);
return 0;
}
Structure. Enter Emplyee code, name, and salary and
count hra, da, pf, net salary using structure.
# include <stdio.h>
int main()
{
struct employee{
int code;
char name[10];
float basic,
hra, da, pf, net;
}emp;
printf("Enter emp. code : ");
scanf("%d",&emp.code);
printf("Enter
emp. Name : ");
fflush(stdin);
gets(emp.name);
printf("Enter
Basic Salary : ");
scanf("%f",&emp.basic);
emp.hra =
emp.basic*10/100;
emp.da =
emp.basic*1.5/100;
emp.pf =
emp.basic*5/100;
emp.net =
emp.basic+emp.hra+emp.da+emp.pf;
printf("\n\tEmp.Code = %d",emp.code);
printf("\n\tEmp.Name = %s",emp.name);
printf("\n\tBasic = %.2f",emp.basic);
printf("\n\tHRA = %.2f",emp.hra);
printf("\n\tDA
= %.2f",emp.da);
printf("\n\tPF = %.2f",emp.pf);
printf("\n\tNet Salary = %.2f",emp.net);
return 0;
}
Structure. Array of Structure.
# include <stdio.h>
int main()
{
struct student{
int rollno;
char name[20];
float percent;
};
struct student
st[5];
int a;
for(a=0;a<5;a++){
printf("Enter Roll no : ");
scanf("%d",&st[a].rollno);
printf("Enter Name : ");
fflush(stdin);
gets(st[a].name);
printf("Enter
Percent : ");
scanf("%f",&st[a].percent);
}
printf("\n\n\t\tRoll no\t\tName\t\tPercentage");
for(a=0;a<5;a++){
printf("\n\t\t%d\t\t%s\t\t%.2f",st[a].rollno,st[a].name,st[a].percent);
}
return 0;
}
float * abc(float * p)
{
return p;
}
Structure. Write a program that accepts number of days
from the user and convert it into years, month and days using structure.
# include <stdio.h>
int main()
{
struct days{
int year,
month, day;
int nday;
}da;
printf("Enter
no of day : ");
scanf("%d",&da.nday);
da.year = da.nday
/ 365;
da.month = da.nday
/ 30;
da.day = da.nday;
printf("\n\n\tYear = %d",da.year);
printf("\n\tMonth = %d",da.month);
printf("\n\tDay = %d",da.day);
return 0;
}
POINTER
Pointer. Write a program using pointer to compute the
sum of 10 elements stored in an array. (Pointer to an array).
# include <stdio.h>
int main()
{
int arr[10];
int sum = 0, a;
int *ptr;
for(a=0;a<10;a++){
printf("Enter any Value : ");
scanf("%d",&arr[a]);
}
ptr = arr;
for(a=0;a<10;a++){
sum = sum +
*ptr;
ptr++;
}
printf("\n\n\tThe Sum of elements is : %d",sum);
return 0;
}
Pointer. Write a program using pointer to determine
the length of a character of a string.(Pointer to string).
# include <stdio.h>
# include <stdlib.h>
int main()
{
int count = 0;
char s[50], *ptr;
printf("\nEnter a string : ");
gets(s);
ptr = s;
while(*ptr != '\0')
{
count++;
ptr++;
}
printf("\n\n\tLength of %s is %d",s,count);
return 0;
}
Pointer. Write a function using pointer to exchange
the values stored in two different locations in the memory.(Passing pointer as
function arguments).
# include <stdio.h>
int main()
{
int x, y, *a,
*b,temp;
printf("Enter
the value for x : ");
scanf("%d",&x);
printf("\nEnter the Value for y: ");
scanf("%d", &y);
printf("\n\nBefore Swapping : ");
printf("\n\tx
= %d",x);
printf("\n\ty = %d",y);
a = &x;
b = &y;
temp = *b;
*b = *a;
*a = temp;
printf("\n\nAfter Swapping : ");
printf("\n\tx= %d",x);
printf("\n\ty
= %d",y);
return 0;
}
Pointer. Write a function day_name that receive a number
n and returns a pointer to a character string containing the name of the
corresponding day.
#include <stdio.h>
int main()
{
int day;
char
*day_name(int), *ptr;
printf("Enter
day number between 1 to 7: ");
scanf("%d",&day);
ptr =
day_name(day);
printf("\n\tDay Name : %s",ptr);
return 0;
}
char *day_name(int day) {
switch(day) {
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
printf("Invalid day number");
}
}
Pointer. Make your own sort function with help of
pointer.
#include <stdio.h>
int main()
{
int arr[10], a;
int sort(int*);
for(a=0;a<10;a++){
printf("Enter 10 number : ");
scanf("%d",&arr[a]);
}
sort(arr);
return 0;
}
int sort(int *arr)
{
int a, b, temp;
for(a=0;a<10;a++){
for(b=a+1;b<10;b++){
if(arr[a]
> arr[b]) {
temp =
arr[a];
arr[a]
= arr[b];
arr[b]
= temp;
}
}
}
for(a=0;a<10;a++){
printf("\n%d ",*arr);
arr++;
}
return 0;
}
Pointer. Write a C program to accept two values and
display addition, substraction, multiplication and division using pointer.
#include <stdio.h>
int main()
{
int *a, *b, x, y;
int add, sub,
mult;
float div;
printf("Enter
any two numbers : ");
scanf("%d
%d",&x, &y);
a = &x;
b = &y;
add = *a + *b;
sub = *a - *b;
mult = *a * *b;
div = *a / *b;
printf("\n\n\tAddition = %d",add);
printf("\n\tSubstraction : %d",sub);
printf("\n\tMultiplication
: %d",mult);
printf("\n\tDivision
: %.2f",div);
return 0;
}
Pointer. Write a C function to accept two values and
swap them using pointer.
#include <stdio.h>
int main()
{
int a, b;
int swap(int *,
int *);
printf("Enter
Value for A : ");
scanf("%d",&a);
printf("\nEnter Value for B : ");
scanf("%d",&b);
printf("\n\nBefore
Swappig Value : ");
printf("\n\tA
= %d",a);
printf("\n\tB
= %d",b);
swap(&a,
&b);
printf("\n\n\tAfter Swapping Value : ");
printf("\n\tA
= %d",a);
printf("\n\tB
= %d",b);
return 0;
}
int swap(int *x, int *y) {
int temp;
temp = *x;
*x = *y;
*y = temp;
return 0;
}
MALLOC. Input N-numbers from keyboard. Print the
number which are greater than average of entered numbers. Use DMA to store
numbers.
# include <stdio.h>
# include <stdlib.h>
int main()
{
int *ptr, a, n,
sum =0;
float avg = 0;
printf("Enter
how many number do you enter ? : ");
scanf("%d",&n);
ptr = (int *)
malloc(sizeof(int) *n);
for(a=0;a<n;a++){
printf("Enter any number : ");
scanf("%d",ptr+a);
sum = sum +
(*ptr + a);
}
avg = sum /
(float) n;
printf("\n\tAverage
of number is %.2f",avg);
return 0;
}
MALLOC. Write a C program to enter N numbers through
keyboard and print the minimum and maximum no.
# include <stdio.h>
# include <stdlib.h>
int main()
{
int *ptr, a, n,
min, max;
printf("ENter
value for N : ");
scanf("%d",&n);
ptr = (int *)
malloc(sizeof(int));
for(a=0;a<n;a++){
printf("ENter number : ");
scanf("%d",ptr + a);
}
min = ptr[0];
max = ptr[0];
for(a=0;a<n;a++){
if(min >
ptr[a])
min =
ptr[a];
if(max <
ptr[a])
max =
ptr[a];
}
printf("\n\t%d is min number",min);
printf("\n\t%d
is max number",max);
return 0;
}
FUNCTIONS
Function. Function without argument, no return value.
# include <stdio.h>
int main()
{
void message(); // Function declaration
printf("\n\n\tBefore calling function");
message(); //
Function Calling
printf("\n\n\tAfter Calling function");
return 0;
}
void message()
{
printf("\n\n\tWithin function message.");
}
Function without argument, with return value.
# include <stdio.h>
int main()
{
int ans;
int square();
ans = square();
printf("\n\tsquare = %d",ans);
return 0;
}
int square()
{
int n, sq;
printf("\nEnter any number : ");
scanf("%d",&n);
sq = n * n;
return sq;
}
Function with argument, no return value.
# include <stdio.h>
int main()
{
void
odd_even(int);
int no;
printf("Enter
any number : ");
scanf("%d",&no);
odd_even(no);
return 0;
}
void odd_even(int no)
{
if(no % 2 == 0)
printf("\tEven Number");
else
printf("\tOdd Number");
}
Function with argument, with return value.
# include <stdio.h>
int main()
{
int a, b, ans;
int multiply(int,
int);
printf("Enter
value for a = ");
scanf("%d",&a);
printf("Enter
value for b = ");
scanf("%d",&b);
ans = multiply(a,
b);
printf("\n\tMultiplication
= %d",ans);
return 0;
}
int multiply(int x, int y)
{
int z;
z = x * y;
return z;
}
Function. Passing Array to a function.
# include <stdio.h>
int main()
{
int arr[10], a;
void show(int[]);
for(a=0;a<10;a++){
printf("Enter any number : ");
scanf("%d",&arr[a]);
}
show(arr);
return 0;
}
void show(int num[])
{
int a;
for(a=0;a<10;a++){
printf("\n\t%d",num[a]);
}
}
Function. Passing structure to a function.
# include <stdio.h>
struct employee
{
int code;
char name[10];
float salary;
};
int main()
{
struct employee
e1;
void display(struct employee);
printf("Enter
Emp. code = ");
scanf("%d",&e1.code);
printf("Enter
Emp. Name = ");
fflush(stdin);
gets(e1.name);
printf("Enter
Salary = ");
scanf("%f",&e1.salary);
display(e1);
return 0;
}
void display (struct employee emp)
{
printf("\n\tEmp. code = %d",emp.code);
printf("\n\tEmp. Name = %s",emp.name);
printf("\n\tEmp. Salay = %.2f",emp.salary);
}
FILE HANDLING
Miscelleneous Functions : delay, clrscr, isaalnum,
isalpha, isdigit, islower, isprint, isspace, isupper, toupper, tolower.
# include <stdio.h>
# include <ctype.h>
int main()
{
char ch;
printf("Enter
any character : ");
scanf("%c",&ch);
if(islower(ch)) {
printf("\n\tLower Case Character ");
printf("\n\tIts Upper Case = %c",toupper(ch));
}
else
if(isupper(ch)) {
printf("\n\tUpper case Character ");
printf("\n\tIts Lower Case = %c",tolower(ch));
}
if(isalpha(ch)) {
printf("\n\tAlphabet");
}
if(isdigit(ch)) {
printf("\n\tNumber or Digit");
}
if(isalnum(ch)) {
printf("\n\tAlphaber or Digit");
}
if(isspace(ch)) {
printf("\n\tSpace Character");
}
if(ispunct(ch)) {
printf("\n\tSpecial Character");
}
if(isprint(ch)) {
printf("\n\tPrintable Character");
}
return 0;
}
Function. Nesting of function.
# include <stdio.h>
int main()
{
void message();
printf("\n\tBefore calling message function");
message();
printf("\n\tAfter calling message function");
return 0;
}
void message()
{
void test();
printf("\n\tBefore
calling test function");
test();
printf("\n\tAfter calling test function");
}
void test()
{
printf("\n\tWithin test function");
}
Register
# include <stdio.h>
int main()
{
register int a;
for(a=1;a<=100;a++){
printf("%d\t",a);
}
return 0;
}
Standard Library Functions : abs, atof, atol, exit,
free, rand.
# include <stdio.h>
# include <stdlib.h>
int main()
{
printf("\n\tabs(-24)
= %d",abs(-24));
printf("\n\tatol(123456789) =
%ld",atol("123456789"));
printf("\n\tatof(3.14) = %f",atof("3.142857"));
printf("\n\trand() = %d",rand());
exit(0);
return 0;
}
Static variable
# include <stdio.h>
int main()
{
int a;
void show();
for(a=0;a<10;a++){
show();
}
return 0;
}
void show()
{
static int b=1;
printf("\n\t%d",b);
b++;
}
String Function : strcpy, strncpy, strcat, strncat,
strchr, stremp, strncmp, strlen, strstr.
# include <stdio.h>
# include <string.h>
int main()
{
char str[40],
newstr[40], str2[40];
printf("Enter
any String : ");
gets(str);
printf("\n\tstrlen(str)
= %d",strlen(str));
strcpy(newstr,
str);
printf("\n\tstrcpy(newstr, str) = %s",newstr);
strncpy(str2, str,
5);
str2[5] =
NULL; // str2[5] = '\0';
printf("\n\tstrncpy(str2,str,5)
= %s",str2);
if(strcmp(str, newstr)
== 0) {
printf("\n\tstrcmp(str,newstr) - Both strings are same");
}
else{
printf("\n\tstrcmp(str,newstr) - Both strings are not same");
}
if(strncmp(str,str2,5) == 0) {
printf("\n\tFirst five character are same");
}
else{
printf("\n\tFirst five character are not same");
}
strcat(str, "
");
strcat(str,str2);
printf("\n\tstrcat(str,str2) = %s",str);
strncat(str,str2,3);
printf("\n\tstrncat(str,str2,3) = %s",str);
printf("\n\tstrchr(str,e) = %s",strchr(str,'e'));
printf("\n\tstrstr(str,ter) =
%s",strstr(str,"ter"));
return 0;
}
Function. I/O Formatting Functions : printf, scanf,
getc, getchar, gets, putc, putchar, puts.
# include <stdio.h>
int main()
{
int n;
char ch;
char str[20];
printf("Enter
any number : ");
scanf("%d",&n);
printf("Enter
any Character : ");
fflush(stdin); // Only for 1
character.
ch = getchar();
printf("Enter
any String : ");
fflush(stdin); // Use Multiple
character.
gets(str);
printf("\n\tNumber = %d",n);
printf("\n\tCharacter = ");
putchar(ch);
printf("\n\tString = ");
puts(str);
return 0;
}
Function. Mathematical Function : ceil, div, exp,
fabs, floor, fmod, log, pow, sqrt.
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
int main()
{
printf("\n\tCeil(12.005) = %f",ceil(12.005));
printf("\n\tFloor(14.95) = %f",floor(14.95));
printf("\n\tSqrt(9) = %f",sqrt(9));
printf("\n\tPow(3,
4) = %f",pow(3, 4));
printf("\n\tExp(1) = %f",exp(1));
printf("\n\tExp(2)
= %f",exp(2));
printf("\n\tDiv(16,
3) = %d",div(16, 3));
printf("\n\tFmod(16.75, 3) = %f",fmod(16.75, 3));
printf("\n\tFabs(-23.75) = %f",fabs(-23.75));
printf("\n\tlog(10)
= %f",log(10));
return 0;
}
float * abc(float * p)
{
return p;
}
File Handling function
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
int main()
{
char
sentence[1000];
FILE *fptr;
fptr =
fopen("f1.txt","w");
if(fptr == NULL) {
printf("Error!");
exit(1);
}
printf("\nEnter
a Sentence : ");
fgets(sentence,
sizeof(sentence), stdin);
fprintf(fptr, "%s", sentence);
fclose(fptr);
return 0;
}
NOTE:- FOR THIS PROGRAM YOU MUST HAVE A TXT
FILE IT'S NAME IS f1.txt and write some
statements like
this....
Hello, Welcome to programming in c.
File Handiling Function. A File named NUMBERS contains
a series of integer numbers. Write a program to read these numbers and then
write all odd number to a file called ODD and all even numbers to a file called
EVEN.
# include <stdio.h>
int main()
{
FILE *f1,*f2,*f3;
int number, a;
f1 =
fopen("DATA","w");
for(a=0;a<=10;a++){
printf("Contents
of DATA File: ");
scanf("%d",&number);
if(number ==
-1) break;
putw(number,
f1);
}
fclose(f1);
f1 =
fopen("DATA","r");
f2 =
fopen("ODD","w");
f3 =
fopen("EVEN","w");
while((number =
getw(f1)) != EOF) {
if(number % 2
== 0)
putw(number, f3);
else
putw(number,f2);
}
fclose(f1);
fclose(f2);
fclose(f3);
f2 =
fopen("ODD","r");
f3 =
fopen("EVEN","r");
printf("\n\nContents
of ODD File : ");
while((number =
getw(f2)) != EOF)
printf("%4d",number);
printf("\n\nContents of EVEN File: ");
while((number =
getw(f3)) !=EOF)
printf("%4d",number);
fclose(f2);
fclose(f3);
return 0;
}
File Handling Function. to enter text to store one txt
file and copy to another txt file using file handling.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h> // For exit()
int main()
{
FILE *fptr1,
*fptr2;
char filename[100],
c;
printf("Enter
the filename to open for reading \n");
scanf("%s", filename);
// Open one file
for reading
fptr1 =
fopen(filename, "r");
if (fptr1 == NULL) {
printf("Cannot open file %s \n", filename);
exit(0);
}
printf("Enter
the filename to open for writing \n");
scanf("%s", filename);
// Open another
file for writing
fptr2 =
fopen(filename, "w");
if (fptr2 == NULL) {
printf("Cannot open file %s \n", filename);
exit(0);
}
// Read contents
from file
c = fgetc(fptr1);
while (c != EOF) {
fputc(c, fptr2);
c =
fgetc(fptr1);
}
printf("\nContents copied to %s", filename);
fclose(fptr1);
fclose(fptr2);
// return 0;
return 0;
}
NOTE:-
FOR THIS PROGRAM
YOU MUST HAVE A TXT FILE.
File Handling Function. Write a C program that reads a
text file and print it into another file.
# include <stdio.h>
int main()
{
FILE *fp;
char s;
fp =
fopen("f.txt","r");
do{
s = getc(fp);
printf("%c",s);
} while(s != EOF);
fclose(fp);
return 0;
}
NOTE :-
FOR THIS PROGRAM
YOU MUST HAVE A TXT FILE THAT NAME IS f.txt
in this txt file must have write some statements.
File Handling Function. Write a C program to read a
file and count how many vowels in that file.
# include <stdio.h>
int main()
{
int c = 0, count =
0;
char s[1000];
printf("Enter
any string : ");
gets(s);
while(s[c] !=
'\0') {
if(s[c] == 'a'
|| s[c] == 'A' |s[c] == 'e'|| s[c] == 'E' ||
s[c]
== 'i' || s[c]== 'I'|| s[c] == 'o'|| s[c] == 'O'
||
s[c] == 'u'|| s[c] == 'U') {
count++;
}
c++;
}
printf("Number of vowels in the string : %d",count);
return 0;
}
File Handling Function. Enter path of txt file and
count how many word in statement, how many word in statement, and how many line
in file
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * file;
char path[100];
char ch;
int characters, words, lines;
/* Input path of
files to merge to third file */
printf("Enter
source file path: ");
scanf("%s", path);
/* Open source
files in 'r' mode */
file = fopen(path,
"r");
/* Check if file
opened successfully */
if (file == NULL) {
printf("\nUnable to open file.\n");
printf("Please check if file exists and you have read
privilege.\n");
exit(EXIT_FAILURE);
}
/*
* Logic to count
characters, words and lines.
*/
characters = words
= lines = 0;
while ((ch =
fgetc(file)) != EOF) {
characters++;
/* Check new
line */
if (ch == '\n'
|| ch == '\0')
lines++;
/* Check words
*/
if (ch == ' '
|| ch == '\t' || ch == '\n' || ch == '\0')
words++;
}
/* Increment words
and lines for last word */
if (characters
> 0) {
words++;
lines++;
}
/* Print file
statistics */
printf("\n");
printf("Total
characters in first statement = %d\n", characters);
printf("Total
words in statement =
%d\n", words);
printf("Total
lines in file = %d\n", lines);
/* Close files to
release resources */
fclose(file);
return 0;
}
NOTE :-
FOR THIS PROGRAM
YOU MUST HAVE A TXT FILE THAT NAME IS f.txt
in this txt file must have write
some statements.
No comments:
Post a Comment