0% found this document useful (0 votes)
34 views

Test 2

The document contains four code snippets that demonstrate basic C programming concepts like calculators, character counting, area and circumference calculations using macros, and checking odd/even numbers. Each code snippet is preceded by comments describing its purpose and followed by sample output.

Uploaded by

sandeep0031
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Test 2

The document contains four code snippets that demonstrate basic C programming concepts like calculators, character counting, area and circumference calculations using macros, and checking odd/even numbers. Each code snippet is preceded by comments describing its purpose and followed by sample output.

Uploaded by

sandeep0031
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Name: sandeep kumar

Class: S.Y.B.C.A
Roll N0: 50

//PROGRAM TO CREATE A FOUR FUNCTION CALCULATOR.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
char operat;
float d;
clrscr();
printf("\nenter the two number.\n");
scanf("%d %d",&a,&b);
printf("\nEnter your Choice:");
printf("\n+ Addition. ");
printf("\n- Subtraction. ");
printf("\n* Multiplication. ");
printf("\n/ Division.\n ");
operat=getch();
switch(operat)
{
case'+': c=a+b;
printf("\nThe Addition is %d",c);
break;
case'-': c=a-b;
printf("\nThe Subtraction is %d",c);
break;
case'*': c=a*b;
printf("\nThe Multiplication is %d",c);
break;
case'/': d=a/b;
printf("The Division is %3.2f",d);
break;
default: printf("Invalid Operator");

}
getch();
}
Output:

Enter the two number.


34
4
Enter your Choice:
+ Addition.
- Subtraction.
* Multiplication.
/ Division.

The Subtraction is 30
Enter the two number.
3
4
Enter your Choice:
+ Addition.
- Subtraction.
* Multiplication.
/ Division.
The Addition is 7

Enter the two number.


3
9
Enter your Choice:
+ Addition.
- Subtraction.
* Multiplication.
/ Division.
The Multiplication is 27

Enter the two number.


9
3
Enter your Choice:
+ Addition
- Subtraction.
* Multiplication.
/ Division.

The Division is 3.00


Name: sandeep kumar
Class: S.Y.B.C.A
Roll N0: 50

//PROGRAM TO COUNT THE NUMBER OF CHARACTER IN AN OUTPUT.

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

void main()
{
long char_count=0;

clrscr();
printf("\nEnter text : Press ^z(ctrl+z) to terminate.\n");

while(getchar()!=EOF)
{
char_count=char_count+1;
}

printf("\nNumber of characters = %1d",char_count);


getch();
}

Output:

Enter text : Press ^z(ctrl+z) to terminate.


window^Z

Number of characters = 6
Name: sandeep kumar
Class: S.Y.B.C.A
Roll N0: 50

//PROGRAM TO CALCULATE AREA & CIRCUMFERANCE OF A CIRCLE


USING MACROS.
#define area(x) (3.14*x*x)
#define circumf(p) (2*3.14*p)
#include<stdio.h>
#include<conio.h>
void main()
{
float rad1,ar,circf,rad2;
clrscr();
printf("\nTo find Area & Circumference of a Circle.\n");
printf("\nEnter the radius of the circle.\n");
scanf("%f",&rad1);
ar=area(rad1);
printf("\nThe Area of Circle is %3.2f",ar);
printf("\n");
printf("\nEnter the circumference of the circle.\n");
scanf("%f",&rad2);
circf=circumf(rad2);
printf("\nThe Circumference of Circle is %3.2f",circf);

getch();
}

Output:

To find Area & Circumference of a Circle.

Enter the radius of the circle.


6.25

The Area of Circle is 122.66

Enter the circumference of the circle.


2.5

The Circumference of Circle is 15.70


Name: sandeep kumar
Class: S.Y.B.C.A
Roll N0: 50

// PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS ODD


OR EVEN.

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

void main()
{
int a,b;

clrscr();
printf ("\nEnter the number = \n");
scanf ("%d",&a);

b=a%2;
if(b==0)
printf ("%d is Even.",a);

else
printf ("%d is Odd.",a);

getch();
}

OUTPUT:

Enter the number = 3


3 is Odd.

Enter the number = 10


10 is Even.

Enter the number = 36


36 is Even.
Name: sandeep kumar
Class: T.Y.B.C.A
Roll N0: 35

// PROGRAM TO COUNT THE NUMBER OF LINE IN A GIVEN TEXT.

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

void main()
{
char inchar;
int line=0;

clrscr();
printf("\nEnter a passage of text : Press ^z(ctrl+z) to exit. \n");

while((inchar=getchar())==' '||inchar=='\t'||inchar=='\n');

while(inchar !=EOF)
{
if(inchar=='\n')
line++;
inchar=getchar();
}

line++;
printf("\nThe number of line in the given passage is : %d",line);
}

Output:

Enter a passage of text:


and
or
last
dot
an
the
for^Z

The number of line in the given passage is : 7


Name: sandeep kumar
Class: S.Y.B.C.A
Roll N0: 50

// PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS ODD


OR EVEN.

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

void main()
{
int a,b;

clrscr();
printf ("\nEnter the number = \n");
scanf ("%d",&a);

b=a%2;
if(b==0)
printf ("%d is Even.",a);

else
printf ("%d is Odd.",a);

getch();
}

OUTPUT:

Enter the number = 3


3 is Odd.

Enter the number = 10


10 is Even.

Enter the number = 36


36 is Even.
Name: sandeep kumar
Class: S.Y.B.C.A
Roll N0: 50

//PROGRAM TO DISPLAY FLOYD`S TRAINGLE.


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,num=1,row;
clrscr();
printf("\nTo display Floyd`s Triangle.\n");
printf("\nEnter the no of rows.\n");
scanf("%d",&row);
printf("\nThe Floyd`s triangle :\n\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
{
printf("%3d",num);
num++;
}
printf("\n");
}
getch();
}

Output:

To display Floyd’s Triangle.

Enter the no of rows.


4

The Floyd`s triangle :


1
2 3
4 5 6
7 8 9 10

You might also like