You are on page 1of 14

WRITE A PROGRAM THAT PRINT hello ON

THE SCREEN
# include <stdio.h>
# include <conio.h>
void main ( )
{
printf (hello);
getch ( );
}
WRITE A PROGRAM WHICH PRINTS THE
MINIMUM AND MAXIMUM VALUES OF AN
INTEGER
# include <stdio.h>
# include <conio.h>
void main ( )
{
printf (Minimum int = %i \n , INT_MIN);
printf (Maximum int = %i, INT_MAX);
getch ( );
}

WRITE A PROGRAM WHICH PRINTS A TEXT


OF 4 LINES CONSISTING OF CHARACTERS,
INTEGER VALUES AND FLOATING POINT
VALUES USING PRINTF STATEMENT.
# include <stdio.h>
# include <conio.h>
void main ( )
{
int east1 = 61;
float north1 = 23.30, north2 = 36.45, east2 =
75.30;
printf (Pakistan is located between %f Degrees
and \n , north1);
printf (%f Degree North latitude and %d \n,
north2, east1);
printf (Degrees and %f Degrees East longitude
in the \n , east2);
printf (northern hemisphere in South-East
Asia. \n);
getch ( );
}
WRITE A PROGRAM THAT READ 2 INTEGERS
AND DISPLAY ONE AS A PERCENTAGE OF
THE OTHER
# include <stdio.h>
# include <conio.h>
void main ( )
{
int val1, val2, percent;
printf (Enter 1st value:);
scanf (%d, &val1);
printf (\n Enter 2nd value:);
scanf (%d, &val2);
percent = (val1 * 100) / val2;
printf (\n %d is %d of %d, val1, percent, val2);
getch ( );

WRITE A PROGRAM THAT PRINT YOUR


NAME AND ADDRESS. USE ONE PRINTF
WITH A NEW LINE CHARACTER IN IT
# include <stdio.h>
# include <conio.h>
void main ( )
{
printf (Muhammad Atif \n Gulberg III,
Lahore);
getch ( );
}
WRITE A PROGRAM TO COMPUTER THE
AREA OF A RECTANGLE
# include <stdio.h>
# include <conio.h>
void main ( )
{
int width, length, area;
width = 15;
length = 40;
area = width * length;
printf (Rectangle width is %d \n, width);
printf (Rectangle length is %d \n, length);
printf (Area of Rectangle is %d \n, area);
getch ( );
}
WRITE A PROGRAM THAT 3 INTEGERS
AND PRINT THEIR SUM
# include <stdio.h>
# include <conio.h>
void main ( )
{
int val1, val2, val3, sum;
printf (Enter 1st value:);
scanf (%d, &val1);
printf (\n Enter 2nd value:);
scanf (%d, &val2);
printf (\n Enter 3rd value:);
scanf (%d, &val3);
sum = val1 + val2+ val3;
printf (Sum of 3 Integers are: %d, sum);
getch ( );
}

WRITE A PROGRAM THAT READS AND


PRINTS
USING
ESCAPE
SEQUENCE.
(ASKING THE NAME, AGE, HEIGHT,
GENDER OF THE STUDENTS USING SCANF
AND PRINTF STATEMENTS
# include <stdio.h>
# include <conio.h>
void main ( )
{
char name [20];
int age;
float height;
char gender [6];
printf (Enter your name:);
scanf (%s, &name);

printf (\n Enter your age:);


scanf (%d, &age);
printf (\n Enter height:);
scanf (%f, &height);
printf (\n Enter your gender: );
scanf ( %s, &gender);
printf (\n \n Your name is %s. , name);
printf (\n You are %d years old. , age);
printf (\n Your height is %f feet. , height);
printf (\n you are a %s person. , gender);
getch ( );
}

WRITE A PROGRAM TO CALCULATE THE


AREA OF A CIRCLE
# include <stdio.h>
# include <conio.h>
void main ( )
{
const float pi = 3.1415926;
float radius, area;
printf (What is the radius of a circle:);
scanf (%f, &radius);
area = pi * radius * radius;
printf (\n \n Area of circle is: %f , area);
getch ( );
}

WRITE A PROGRA THAT READ TWO


INTEGER AND DISPLAY WHICH ONE IS
THE LARGEST
# include <stdio.h>
# include <conio.h>
void main ( )
{
int a, b;
printf (Enter 1st value:);
scanf (%d, &a);
printf (\n Enter 2nd value:);
scanf (%d, &b);
if (a > b)
printf (\n \n %d is the largest integer value ,
a);
else
printf (\n \n %d is the largest integer value ,
b);
getch ( );
}

WRITE
A
PROGRAM
WHICH
USES
OPERATORS (CALCULATE THE AREA OF A
TRIANGLES, VOLUME OF SPHERE AND
ARRANGE THE RESULTANT VALUES IN
ASCENDING ORDER)
# include <stdio.h>
# include <conio.h>
# include <maths.h>
void main ( )
{
float a, b, c, s, area, d, vol;
printf (Enter triangle side A:);
scanf (%f, &a);
printf (\n Enter triangle side B:);
scanf (%f, &b);
printf (\n Enter triangle side C:);
scanf (%f, &c);
printf (\n Enter diameter of sphere:);
scanf (%f, &d);
s = (a + b + c) / 2;
area = sqrt (s * (s a) * (s b) * (s c));
vol = (3.14 / 6) * (d * d * d);
if (vol > area)
{
printf ( \n Area of triangle = %f, area);
printf ( \n Volume of sphere = %f, vol);
}
else

WRITE A PROGRAM THAT READ 5


NUMBERS AND COMPUTER THE AVERAGE,
MAXIMUM AND MINIMUM VALUES
# include <stdio.h>
# include <conio.h>
void main ( )
{
int n, sum = 0, max = 0, min = 0, i;
float avg;
for (i = 1; I < = 5; i++)
{
printf ( \n Enter Number: );
scanf (%d, &n);
if (min < n)
{
min = n;
}
if (max > n)
{
max = n;
}
sum = sum + n;
}
printf (\n Largest = %d, Smallest = %d, ,
min, max);
avg = sum / 5;
printf (\n \n Average = %f , avg);
getch ( );

{
printf ( \n Volume of sphere = %f, vol);
printf ( \n Area of triangle = %f, area);
}
getch ( );
}
WRITE A PROGRAM THAT PRINT A SIMPLE
TRIANGLE OF ASTERISKS
# include <stdio.h>
# include <conio.h>
void main ( )
{
int i, j;
for (i = 1; i < = 10; i++)
{
for (j = 1; j < = I; j++)
{
printf ( * );
}
printf ( \n);
}
getch ( );
}

WRITE
A PROGRAM
TO
PRINT THE
NUMBERS BETWEEN 1 TO 10, ALONG WITH
AN INDICATION OF WHETHER EACH IS EVEN
OR ODD
# include <stdio.h>
# include <conio.h>
void main ( )
{
int i;
for (i = 1; i < = 10; i++)
{
if ( I % 2 == 0)
{
printf (%d is even \n, i);
}
else
{
printf(%d is odd \n, i);
}
}
getch ( );
}

WRITE A PROGRAM THAT PRINT EVEN


NUMBERS FROM ANY RANGE AND FIND
SUM OF ALL NUMBERS USING WHILE
LOOP STATEMENT
# include <stdio.h>
# include <conio.h>
void main ( )
{
int a, n, sum;
printf (Enter Start Number:);
scanf (%d, &n);
printf ( \n Enter Last Number:);
scanf (%d, &a);
while (n < = a)
{
printf( %d \n , n);
sum + = n;
n + = 1;
}
printf (Sum from %d to %d = %d , n, a,
sum);
getch ( );
}
WRITE A PROGRAM WHICH FINDING THE
FACTORIAL OF N USING WHILE LOOP,
READ VALUE OF N USING SCANF, AND
PRINT FACTORIAL OF VARIOUS N.
# include <stdio.h>
# include <conio.h>
void main ( )
{
int n, result = 1, counter = 1;
printf (Enter the value of N:);
scanf (%d, &n);
while (counter < = n)
{
result = counter * result;
counter + = 1;

WRITE A PROGRAM WHICH USES WHILE


LOOP AND NESTED WHILE LOOP (USE FOR
LOOP AND CONTINUE THE PROCESS IN
WHILE LOOP SATISFYING THIS CONDITION)
# include <stdio.h>
# include <conio.h>
void main ( )
{
int a, b, count;
for (x = 1; x < = 2; x++)
{
b = 1;
while (b< = 5)
{
count = 1;

WRITE
A
PROGRAM
TO
GENERATE
MULTIPLICATION TABLE OF NUMBER
USING FOR LOOP
# include <stdio.h>
# include <conio.h>
void main ( )
{
int n, table, i;
printf (Enter Number:);
scanf (%d, &n);
for (i = 1; i < = 10; i++)
{
table = n * i;
printf( \n %d x %d = %d, n, i, table);
}
getch ( );
}

while (count < = b)


{
Printf(%d, count);
count ++;
}
printf (\n);
loop ++;
}
}
getch ( );
}
WRITE
A
PROGRAM
THAT
DRAW
A
CHECKBOARD AND PRINT IT USING IF
ELSE
STATEMENT,
AND
EXTEND
THE
PROGRAM USING NESTED IF ELSE.
# include <stdio.h>
# include <conio.h>
void main ( )
{
int board, i, j, k;
board = 0;
k = 0;
printf (How many biff do you want the
square:);
scanf (%d, &board);
printf ( \n );
for (i = 0; i < board; i++)
{
for (j = 0; j < board; j++)
{
if (k == 0)
{
printf (_);
k = 1;
}
else
{
if (k == 1)
{
printf (#);
k = 0;
}
}
}
printf ( \n);
}
getch ( );
}
WRITE A PROGRAM WHICH USES A
SWITCH STATEMENT AND BREAKS THE
PROGRAM IF CERTAIN CONDITION IS
OBSERVED. REPEAT THE PROGRAM WITH
CASE STATEMENT.
# include <stdio.h>
# include <conio.h>
void main ( )
{
int month;
do
{
printf (\n Type the number of a month:);
scanf (%d, &month);

}
printf(\n Factorial of N is : %d, result);
getch ( );
}

WRITE A PROGRAM TO READ AN INTEGER


VALUE AND PRINT OUT THE PRICE OF
DIFFERENT
FRUITS
USING
SWITCH
STATEMENT.
# include <stdio.h>
# include <conio.h>
void main ( )
{
int x;
printf (What fruit price you want to see?);
printf (\n (1)
Oranges,
(2)
Apples);
printf (\n (3)
Bananas,
(4)
Cherries);
printf (\n Enter your choice:);
scanf (%d, &x);
switch (x)
{
case 1:
printf (\n Oranges are 20 per KG);
break;
case 2:
printf (\n Apples are 40 per KG);
break;
case 3:
printf (\n Bananas are 15 per KG);
break;
case 4:
printf (\n Cherries are 150 per KG);
break;
default:
printf (\n Sorry, We are Out of Stock);
}
getch ( );
}
WRITE A FUNCTION CELSIUS TO CONVERT
DEGREES
FAHRENHEIT
TO
DEGREES
CELSIUS.
# include <stdio.h>
# include <conio.h>
float Celsius (int x);
int main ( )
{
int fah;
float cel;
printf (\n Enter Temperature in Fahrenheit: );
scanf (%d, &fah);
cel = Celsius (fah);
printf ( \n Temperature in Celsius is %f, cel);

printf (Name of Month is : %d, month);


switch (month)
{
case 1:
printf (JANUARY);
break;
case 2:
printf (FEBRUARY);
break;
case 3:
printf (MARCH);
break;
case 4:
printf (APRIL);
break;
case 5:
printf (MAY);
break;
case 6:
printf (JUNE);
break;
case 7:
printf (JULY);
break;
case 8:
printf (AUGUST);
break;
case 9:
printf (SEPTEMBER);
break;
case 10:
printf (OCTOBER);
break;
case 11:
printf (NOVEMBER);
break;
case 12:
printf (DECEMBER);
break;
default:
printf (Unknown);
continue;
}
} while (month < 1 || month > 12);
getch ( );
}
WRITE A FUNCTION, WHICH GENERATES
FUNCTION FACTORIAL OF N AND CALLS
THIS FUNCTION IN THE MAIN PROGRAM.
# include <stdio.h>
# include <conio.h>
int factorial (int x);
int main ( )
{
int n, f;
printf (Enter the value of N: );
scanf (%d, &n);
f = factorial (n;
printf ( \n Factorial of N is: %d, f);
return 0;
getch ( );
}

return 0;
getch ( );
}
float celsius (int x)
{
float y;
y = 5 * (x 32) / 9;
return y;
}

WRITE
A
PROGRAM
WHICH
USES
MULTIPLE ARGUMENTS IN A FUNCTION
(DEVELOP A USER-DEFINED FUNCTION TO
GENERATE A RECTANGLE). USE THE
FUNCTION FOR PASSING ARGUMENTS TO
DRAW THE FUNCTION FOR PASSING
ARGUMENTS TO DRAW DIFFERENT SIZES
OF RECTANGLES AND SQUARES.
# include <stdio.h>
# include <conio.h>
void box (int length, int width);
int main ( )
{
box (5, 5);
box (5, 10);
box (7, 7);

int factorial (int x)


{
int i, fact = 1;
for (i = 1; i <=x; i++)
fact = fact * i;
return fact;
}

WRITE A PROGRAM TO FIND THE SUM OF


TWO VALUES GIVEN BY USER
# include <stdio.h>
# include <conio.h>
void main ( )
{
int a, b, sum;
printf (Enter first value:);
scanf (%d, &a);
printf (Enter second value:);
scanf (%d, &b);
sum = a +b;
printf (Sum are : %d, sum);
getch ( );
}

WRITE A PROGRAM THAT GETS THE


TEMPERATURE FROM USER IN CELSIUS AND
CONVERT IT.
# include <stdio.h>
# include <conio.h>
void main ( )
{
float C, F;
printf (Enter Temperature in Celsius:);
scanf (%f, &C);
F = 9/5 * (C + 32);
printf (Temperature in Fahrenheit = %f, F);
getch ( );
}

box (3, 8);


return 0;
getch ( );
}
void box (int length, int width)
{
int a, b, x;
for (a = 1; a< = width; a++)
printf (*);
for (b = 1; b< = length; b++)
{
x = 0;
printf ( \n * );
while (x < = (width 3))
{
x = x + 1;
printf ( );
}
Printf ( * );
}
printf ( \n );
for (a = 1; a<=width; a++)
printf ( * );
printf ( \n );
}
WRITE A PROGRAM THAT INPUTS BASE
AND HEIGHT FROM THE USER AND
CALCULATE AREA OF A TRIANGLE BY
USING FORMULA:
AREA = * (BASE
* HEIGHT)
# include <stdio.h>
# include <conio.h>
void main ( )
{
int B, H, AREA;
printf (Enter Base:);
scanf (%d, &B);
printf (Enter Height:);
scanf (%d, &H);
AREA = * (B * H);
printf (AREA OF TRIANGLE IS: %d, AREA);
getch ( );
}
WRITE A PROGRAM THAT INPUTS RADIUS
OF SPHERE FROM THE USER. CALCULATE
ITS VOLUME AND SPHERE AREA USING
FORMULA
(AREA
=
4r2)
3
(Circumference = 4/3 * (r )
# include <stdio.h>
# include <conio.h>
void main ( )
{
int r, A, C;
printf (Enter Radius:);
scanf (%d, &r);
A = 4 * 3.14 * r *r;
printf (Area: %d, A);
C = 4/3 * 3.14 * r * r * r;
printf (Circumference: %i, C);
getch ( );
}

WRITE A PROGRAM TO ENTER WEIGHT IN


POUND AND CONVERT IT INTO KG (KG
=
2.2 lb)
# include <stdio.h>
# include <conio.h>
void main ( )
{
int p, kg;
printf (Enter Weight in Pound:);
scanf (%d, &p);
kg = 2.2 * p;
printf (Weight in KG = %d, kg);
getch ( );
}

WRITE A PROGRAM TO CONVERT KILOGRAM


TO PIND USING WHILE LOOP. IN THIS
PROGRAM ZERO SIGNAL THE END OF INPUT
# include <stdio.h>
# include <conio.h>
void main ( )
{
int p, kg;
while (kg ! = 0)
{
printf (Enter Weight in KG:);
scanf (%d, &kg);
p = kg / 2.2;
printf (Weight in pound = %d, p);
}
getch ( );
}
WRITE A PROGRAM TO DISPLAY TRIANGLE
OF ASTERIK IN REVERSE
# include <stdio.h>
# include <conio.h>
void main ( )
{
int i, j, k;
for (i = 5; i >=1; i--)
{
for (j = 1; j <= 5 i; j++)
{
printf ( );
}
for (k = 1; k<=i; k++);
{
printf(*);
}
printf (\n);
}
getch ( );
}
WRITE A PROGRAM TO ENTER A YEAR AND
FIND IT IS LEAP YEAR OR NOT.
# include <stdio.h>
# include <conio.h>
void main ( )

WRITE A PROGRAM TO GENERATE TABLE


BY GETTING START AND ENDING VALUE
FROM USER USING FOR LOOP.
# include <stdio.h>
# include <conio.h>
void main ( )
{
int n, e, i, tab;
printf (Enter Number for table:);
scanf (%d, &n);
printf (Enter end value:);
scanf (%d, &e);
for (i = 1; i < = e; i++)
{
tab = n * i;
printf (%d X %d = %d, n, i, tab);
}
getch ( );
}
WRITE
A
PROGRAM
TO
DISPLAY
FACTORIAL USING DO-WHILE LOOP
# include <stdio.h>
# include <conio.h>
void main ( )
{
int n, i, fact= 1;
printf (Enter the value of N:);
scanf (%d, &n);
do
{
fact = fact * i;
i++;
} while ( i < = n);
printf(\n Factorial of N is : %d, fact);
getch ( );
}
WRITE A PROGRAM TO DISPLAY a z
CHARACTER.
# include <stdio.h>
# include <conio.h>
void main ( )
{
char i;
i = a;
do
{
printf (%c, i);
i ++;
}
While (i <= z);
getch ( );
}

WRITE A PROGRAM TO ENTER TWO


NUMBERS AND FIND THE LARGEST
NUMBER
USING
CONDITIONAL
OPERATOR.
# include <stdio.h>

{
int year;
printf (Enter Year:);
scanf (%d, &year);
if (year % 4 == 0)
{
Printf (Leap Year);
}
else
{
printf(Not Leap Year);
}
getch ( );
}
WRITE A PROGRAM THT INPUT THREE
NUMBERS AND FIND THE LARGEST NUMBER
# include <stdio.h>
# include <conio.h>
void main ( )
{
int n, result = 1, counter = 1;
printf (Enter the value of N:);
scanf (%d, &n);
while (counter < = n)
{
result = counter * result;
counter + = 1;
}
printf(\n Factorial of N is : %d, result);
getch ( );
}

WRITE
A
PROGRAM
TO
ENTER
A
CHARACTER AND FIND WHETHER IT IS
VOWEL OR NOT USING SWITCH STATEMENT.
# include <stdio.h>
# include <conio.h>
void main ( )
{
char ch;
printf (Enter the Character:);
scanf (%c, &ch);
switch (ch)
{
case A:
case a:
printf (Vowel);
break;
case E:
case e:
printf (Vowel);
break;

# include <conio.h>
void main ( )
{
int a, b;
printf (Enter two Numbers:);
scanf (%d %d, &a, &b);
a>b? printf(%d is larger number,
printf(%d is larger number, b);
getch ( );
}

a);

WRITE A PROGRAM THAT INPUT THREE


NUMBERS AND FIND THE LARGEST
NUMBER
# include <stdio.h>
# include <conio.h>
void main ( )
{
int a, b, c;
printf (Enter first number:);
scanf (%d, &a);
printf (Enter second number:);
scanf (%d, &b);
printf (Enter three number:);
scanf (%d, &c);
if (a >b && a>c)
{
printf(%d is greater number, a);
}
elseif (b>a && b>c)
{
printf (%d is greater number, b);
}
else
{
printf (%d is greater number, c);
}
getch ( );
}
WRITE A PROGRAM TO ENTER THE INPUT
NUMBER
AND
INTERCHANGE
EACH
OTHER WITHOUT USING THIRD VARIABLE.
#include <stdio.h>
#include <conio.h>
int main( )
{
int x, y;
printf("Enter First Value:);
scanf("%d, x);
printf("Enter second Value:);
scanf("%d, y);
printf("Before Swapping: x = %d, y = %d", x, y);
x = x + y;
y = x - y;
x = x - y;
printf("After Swapping: x = %d, y = %d", x, y);

case I:
case i:
printf (Vowel);
break;
case O:
case o:
printf (Vowel);
break;
case U:
case u:
printf (Vowel);
break;
default:
printf (Not Vowel);
break;
}
getch ( );
}
WRITE A PROGRAM THAT INTERCHANGE
VALUES OF TWO VARIABLES BY USING THIRD
VARIABLE.
#include <stdio.h>
#include <conio.h>
int main( )
{
int x, y, temp;
printf("Enter the value of x and y\n");
scanf("%d%d", &x, &y);
printf("Before Swapping\nx = %d\ny =
%d\n",x,y);
temp = x;
x = y;
y = temp;
printf("After Swapping\nx = %d\ny =
%d\n",x,y);
getch ( );
return 0;
}

getch ( );
return 0;
}

WRITE A PROGRAM THAT READ A PHRASE


AND PRINT THE NUMBER OF UPPERCASE
AND LOWERCASE.
#include <stdio.h>
#include <conio.h>
int main( )
{
int Lcount = 0, Ucount = 0;
char ch;
printf("Enter the Phrase");
while ((ch = getche) != \n)
{
if (ch == A && ch < Z)
{
Ucount = Ucount+1;
}
if (ch == a && ch < z)
{
Lcount = Lcount+1;
}
}
printf("\nUpparcase letter = %d, Ucount);
printf("\nLowercase letter = %d, Lcount);
getch ( );
return 0;

WRITE A PROGRAM THAT READ TWO


INTEGER AND PRINT THEIR GREATEST
COMMON DIVISOR.
#include <stdio.h>
#include <conio.h>
int main( )
{
int n1, n2, i, GCD = 0;
printf("Enter two Number:");
scanf("%d %d", & n1, & n2);

}
WRITE A PROGRAM THAT PRINT ALL ODD
NUMBERS LESS THAN 100 SKIPING
THOSE THAT ARE EXACTLY DIVISIBLE BY
7.
#include <stdio.h>
#include <conio.h>
int main( )
{
int i;
for (i = 1; i <= 99; i++)
{

for (i = 1; i <= n1 && i <=n2; i++)


{
if (n1 % i == 0 && n2 % i == 0)
GCD = i;
}
printf("\n GCD of %d and %d = %d, n1, n2,
GCD);
getch ( );
return 0;
}
WRITE A PROGRAM THAT INPUT THE USER
TO ENTER A PHRASE AND COUNT THE WORD.
#include <stdio.h>
#include <conio.h>
int main( )
{
char ch;
int Ch_Count, Word_Count;
Ch_Count = 0, Word_Count = 0;
printf("Enter Phrase:");
while ((ch = getche) != \r)
{
Ch_Count = Ch_Count+1;
if (ch == )
Word_Count = Word_Count+1;
}
printf("\nCharacter Count = %d, Ch_Count);
printf("\nWord Count = %d, Word_Count);
getch ( );
return 0;
}
WRITE A PROGRAM TO FIND DENSITY OF A
SOLID CYLINDER USING FUNCTION (d = m /v)
#include <stdio.h>
#include <conio.h>
int density (int m, int v);
int main( )
{
int a, b;
printf ("Enter Mass value:");
scanf (%d, &a);
printf (Enter Volume value:);
scanf (%, &b);
density (a, b);
getch ( );
return 0;
}
int density (int m, int v)
{
int d;

if (i % 7 == 0)
printf (%d \n, i);
}
getch ( );
return 0;
}

WRITE
A
PROGRAM
THAT
READS
TEMPERATURE AND PRINT A DIFFERENT
MESSAGES.
#include <stdio.h>
#include <conio.h>
int main( )
{
int temp;
printf("Enter Temperature:");
scanf (%d, & temp);
if (temp > 35)
printf(It is Hot);
elseif (temp > 20)
printf (Nice Day);
else
printf(It is Cold);
getch ( );
return 0;
}

WRITE A PROGRAM TO
DISTANCE WHERE
S = Vt + at2
#include <stdio.h>
#include <conio.h>
int distance (int v, int t, int a);
int main( )
{
int b, c, d;
printf("Enter the value of V:");
scanf (%d, &b);
printf("Enter the value of t:");
scanf (%d, &c);
printf("Enter the value of a:");
scanf (%d, &d);
distance (b, c, d);
getch ( );
return 0;
}
int distance (int v, int t, int a)

FIND

THE

d = m/v;
printf (Density of Cylinder = %d, d);
}

WRITE A PROGRAM TO GET A NUMBER FROM


THE USER AND DISPLAY ITS SQUARE AND
CUBE USING FUNCTION.
#include <stdio.h>
#include <conio.h>
int square (int a);
int cube (int a);
int main( )
{
int b;
printf("Enter the Number:");
scanf (%d, &b);
square (b);
cube (b);
getch ( );
return 0;
}
int square (int a)
{
int S;
S = a * a;
printf (Square = %d, S);
}
int cube (int a)
{
int C;
S = a * a * a;
printf (Cube = %d, C);
}
WRITE A PROGRAM THAT INPUT TWO
NUMBERS IN MAIN FUNCTION AND PASSES
THE NUMBER TO A FUNCTION. THE FUNTION
RETURNS THE MAXIMUM NUMBER BACK TO
THE MAIN FUNCTION.
#include <stdio.h>
#include <conio.h>
int Number (int a, int b);
int main( )
{
int c, d, e;
printf("Enter the 1st Number:");
scanf (%d, &c);
printf("Enter the 2nd Number:");
scanf (%d, &d);
e = Number (c, d);

{
int S;
S = v*t + a*t*t;
printf (Distance = %d, S);
}
WRITE A PROGRAM TO GET A NUMBER
AND FIND ITS SQUARE AND FUNCTION
ALSO RETURN A VALUE.
#include <stdio.h>
#include <conio.h>
int square (int a);
int main( )
{
int b, Sq;
printf("Enter the Number:");
scanf (%d, &b);
Sq = square (b);
printf (Square of Given Number:%d, Sq);
getch ( );
return 0;
}
int square (int a)
{
int S;
S = a * a;
return (S);
}

WRITE A PROGRAM THAT ADD DIGITS OF


NUMBER.
#include <stdio.h>
#include <conio.h>
int main( )
{
int n, sum = 0, remainder;
printf("Enter an integer\n");
scanf("%d", &n);
while (n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
printf("Sum of digits of %d = %d\n", n, sum);
getch ( );

printf (Maximum Number:%d, e);


getch ( );
return 0;
}
int Number (int a, int b)
{
if (a > b)
return (a);
else
return (b);
}
WRITE A PROGRAM THAT TAKES NUMBER BY
USER AND DISPLAY THEIR SUM
#include <stdio.h>
#include <conio.h>
int main( )
{
int n, sum = 0, c, value;
printf("Enter the number of integers you want to
add\n");
scanf("%d", &n);
printf("Enter %d integers\n",n);
for (c = 1; c <= n; c++)
{
scanf("%d", &value);
sum = sum + value;
}
printf("Sum of entered integers = %d\n",sum);
getch ( );
return 0;
}
WRITE A PROGRAM TO PRINT DIAMOND
PATTERN
#include <stdio.h>
#include <conio.h>
int main()
{
int n, c, k, space = 1;
printf("Enter number of rows\n");
scanf("%d", &n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2*k-1; c++)
printf("*");
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{

return 0;

WRITE A PROGRAM THAT TAKES NUMBER AND


REVERSE IT.
#include <stdio.h>
#include <conio.h>
int main()
{
int n, reverse = 0;
printf("Enter a number to reverse\n");
scanf("%d", &n);
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
printf("Reverse of entered number is =
%d\n", reverse);
getch ( );
return 0;
}

WRITE A PROGRAM TO FIND PRIME


NUMBER
#include <stdio.h>
#include <conio.h>
int main( )
{
int n, i = 3, count, c;
printf("Enter the number of prime numbers
required\n");
scanf("%d",&n);
if ( n >= 1 )
{
printf("First %d prime numbers are :\n",n);
printf("2\n");
}
for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;

for (c = 1; c <= space; c++)


printf(" ");
space++;
for (c = 1 ; c <= 2*(n-k)-1; c++)
printf("*");
printf("\n");
}
getch ( );
return 0;
}
WRITE A PROGRAM THAT PRINT ASCII CODE
FOR ENTER CHARACTER
#include <stdio.h>
# include <conio.h>
int main( )
{
char c;
printf("Enter a character: ");
scanf("%c",&c);
/* Takes a character from
user */
printf("ASCII value of %c = %d", c, c);
getch ( );
return 0;
}
WRITE A PROGRAM TO FIND THAT THE
ENTER VALUE IS CHARACTER OR NOT
#include <stdio.h>
#include <conio.h>
int main( )
{
char c;
printf ("Enter a character: ");
scanf ("%c", &c);
if( (c>='a' && c<='z') || (c>='A' && c<='Z'))
{
printf ("%c is an alphabet.", c);
}
else
{
printf ("%c is not an alphabet.", c);
}
getch ( );
return 0;
}

WRITE A PROGRAM THAT COUNT DIGITS IN

}
if ( c == i )
{
printf("%d\n",i);
count++;
}
i++;

}
getch ( );
return 0;

}
WRITE A PROGRAM THAT PRINT ASCII
CHARACTER FOR ENTERED VALUE
#include <stdio.h>
# include <conio.h>
int main( )
{
int var1;
printf (Enter value:);
scanf (%d, &var1);
printf("\n Character of ASCII value: %c",
var1);
getch ( );
return 0;
}
WRITE
A
PROGRAM
TO
DISPLAY
CHARACTER FROM A TO Z USING LOOPS
EITHER IN UPPERCASE OR LOWERCASE
DEPENDING UPON THE DATA FROM USER
#include <stdio.h>
#include <conio.h>
int main( )
{
char c;
printf("Enter u to display characters in
uppercase and l to display in lowercase: ");
scanf("%c", &c);
if(c=='U' || c=='u')
{
for(c='A'; c<='Z'; ++c)
printf("%c", c);
}
if (c=='L' || c=='l')
{
for(c='a'; c<='z'; ++c)
printf("%c", c);
}
if (c!='U' || c!='L' || c=='u' || c=='l')
printf("Error !!!");
getch ( );
return 0;
}
WRITE A PROGRAM THAT PRINT ALL

A NUMBER
#include <stdio.h>
#include <conio.h>
int main( )
{
int n, count=0;
printf ("Enter an integer: ");
scanf ("%d", &n);
while (n!=0)
{
n / = 10;
/* n=n/10 */
++count;
}
printf ("Number of digits: %d", count);
getch ( );
return 0;
}
WRITE PROGRAM TO FIND GROSS SALARY OF
A PERSON
#include <stdio.h>
#include <conio.h>
int main( )
{
int gross, salary, basic, da, ta;
printf ("Enter basic salary : ");
scanf ("%d", &basic);

da = (10 * basic) / 100;


ta = (12 * basic) / 100;
gross_salary = basic + da + ta;
printf ("\n Gross salary : %d", gross_salary);
return (0);

WRITE PROGRAM TO PRINT PYRAMID OF


ASTERIK
#include <stdio.h>
#include <conio.h>
int main( )
{
int i, j, r, k=0;
printf("Enter the number of rows: ");
scanf("%d", &r);
for (i=1; i<=r; i++)
{
for (j =1; j <= r-i ; j++)
{
printf (" ");
}

ASCII CHARACTER
#include <stdio.h>

#include <conio.h>
int main( )
{
int i;
for(i=0;i<=255;i++)
printf("ASCII value of character %c: %d\n", i,
i);
getch ( );
return 0;
}

WRITE
A
PROGRAM
TO
COMPUTE
REMAINDER AND QUOTIENT
#include <stdio.h>
#include <conio.h>
int main( )
{
int dividend, divisor, quotient, remainder;
printf ("Enter dividend: ");
scanf ("%d", &dividend);
printf ("Enter divisor: ");
scanf ("%d", &divisor);
quotient = dividend / divisor;
remainder = dividend % divisor;
printf ("Quotient = %d\n", quotient);
printf ("Remainder = %d", remainder);
getch ( );
return 0;
}

while (k != 2 * i-1)
{
printf ("*");
K++;
}
k=0;
printf("\n");
}
getch ( );
return 0;
}

You might also like