C- Assignment1

PART -A

Qno.1: Write an algorithm to convert the temperature in Fahrenheit into Celsius.
ANSWER:
Start the program
Step 1- Take input (temperature in Fahrenheit)
Step 2- (f-32)=a, we store in a;
Step 3- a*0.56=c;
Step 4- print c(output);

Qno.2: Draw the flowchart for simulating a simple calculator performing +,-, /?
Answer:

(a

yes

NO
Yes

yes NO

NO

QNO.3: Differentiate between Pseudo code and Algorithm?

Answer:
Pseudo code is an imitation of actual computer instructions. It is written in ordinary natural language (e.g., English, French, German, etc).
Where as an Algorithm refers to the logic of a program. It is a step-by-step description of how to arrive at a solution to a given problem.
Pseudo code uses a structure that resembles computer instructions. When a programmer uses pseudo code for program planning, he/she can concentrate solely on developing the logic of the program without worrying about the syntax. Because pseudo code does not have any syntax rules for formulating instructions.
Where as in algorithm is not so. When a programmer uses algorithm for program, he/she does not concentrate only logic of the program but also think about their syntax.

Qno.4: – Company X sells merchandise to wholesale and outlets .Wholesale customers receives a 2% discount on all orders. The company also encourages both wholesale and retail customers to pay the cash on delivery by offering a 2% discount for this method of payment .Another 2% discount is given on orders of 50 or more unit’s .Each column represents a certain type of order? Draw the decision table?
Answer:
Discount to whole sale =2%
Discount on paying cash on delivery =4%
If so or more unit Order in given =6%

If merchandise is whole sale
Y Y N N
merchandise is outlet N N Y Y
payment by cash
Y N Y N
unit greater the 50
N Y N Y

discount is 2 %
 
discount is 4 %
 
discount is 6 %
 

PART-B

Q1: – Given the string “WORD POCESSING” Write a program to read the string from the terminal and display the same in the following format?
(a) WORD PROCESSING
(b) WORD
PROCESSING
(c) W.P

#include
#include
void main()
{
int i,j=0;
char a[50];
clrscr();
for(i=0;i<=50;i++)
{
scanf("%c",&a[i]);
{
if(a[i]=='\n')
goto label;
}
j=j+1;
}
label:
printf("\n1.\t");
for(i=0;i<=j;i++)
{
printf("%c",a[i]);
if(a[i]==' ')
{
printf("\t");
}
}
printf("\n2.\t");
for(i=0;i<=j;i++)
{
printf("%c",a[i]);
if(a[i]==' ')
{
printf("\n\t");
}
}
printf("\n3.\t");
{
printf("%c.%c.",a[0],a[5]);
}
getch();
}

Qno.2: – Write a program to swap the values of two variables with and without using third variable.
#include
#include

void main( )

{

int a,b;

printf(“\n\n\tEnter the two number”);
scanf(“%d%d”,&a,&b);
printf(“\nThe number you entered is a=%d, b=%d”,a,b);
a=a+b;
b=a-b;
a=a-b;
printf(“\n The number after swapping isa=%d b=%d”,a,b);
getch();
}

Qno.3: Write a program to make a menu driven program to perform addition, subtraction, multiplication and division of two numbers.
Answer:
#include
#include
#include
void main()
{
int I,j,n;
int ch;
clrscr();
do
{
printf(“\n \n \t Enter1st number”);
scanf(“%d”, &i);
printf(“\n \n \tEnter 2nd number”);
scanf(“%d”, &j);
printf(“\n \n \n \n \t What do you want to do”);
printf(“\n \n \t Enter 1 for Addition”);
printf(“\n \n \t Enter 2 for subtraction”);
printf(“\n \n \t Enter 3 for multiplication”);
printf(“\n \n \t Enter 4 for Division”);
scanf(“%d”,&n);
switch(n)
{
case 1:
res=i+j;
printf (“\n \n \n \n \t Your Result is:%d”,res );
break;

case 2:
res=i-j;
printf (“\n \n \n \n \t Your Result is:%d”,res );
break;
case 3:
res=i*j;
printf (“\n \n \n \n \t Your Result is:%d”,res );
break;
case 4:
res=i/j;
printf (“\n \n \n \ n\t Your Result is:%d”,res );
break;
default:
printf(“\n \n \n \n\n Please Enter Valid Number “);

}
printf(“\n \n \n \n \t Do you want to continue:”);
printf(“\n \n \n \t Enter 1 for Continue”);
printf(“\n \n \n \n \t Enter 2 for Exit”);
scanf(“%d”,&ch);
}

while(ch==1);

getch();

}

Qno.4: Write a program that will read a positive integer and determine and print its binary equivalent.
Answer:
/* Proram is written by MANISH KR. SINGH */
#include
#include
void showbits(int h)
{
if(h==1)
printf(“%d”,h);
else
{
showbits(h/2);
printf(“%d”,h%2);
}
}
void main()
{
int n;
void showbits(int h);
clrscr();
printf(“Num?”);
scanf(“%d”,&n);
printf(“\nBin eq of %d is “,n);
showbits(n);
getch();
}

Qno.5: Write a program to generate the following pattern:

1
0 1
1 0 1
0 1 0 1
1 0 1 0 1

Answer:
/* Proram is written by MANISH KR. SINGH */

#include
#include
void main()
{
int i, j, n, k=1;
clrscr();
Printf(“\n\n\t Enter the number of term”);
Scanf(“%d”,&n);
for(i=0;i<=n;i++)
{
for(j=0; j<=i; j++)
{
if(k==0)
k=i;
else
k=0;
printf(“%d”,k)
}
if(i%2==0)
k=0;
else
k=1;
printf(“\n”);
}
getch();
}

Qno. 6: Write a program to generate the following pattern:
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
Answer:
/* Proram is written by MANISH KR. SINGH */
#include
#include
void main()
{
int i, j , n, k;
clrscr();
printf(“\n\n\t Enter the value of n:”);
scanf(“%d”,&n);
printf(“\t”);
printf(“f\n”);
for(i=2; i<=n; i++)
{
for(j=1; j<=n+2; j++)
{
printf(“ “);
}
–t;
k=1;
do
{
printf(“%d”,t);
–p;
}
while(k<=1);
do
{
printf(“%d”,p);
p++;
}
while(k<=i);
printf(“\n”);
}
getch();
}

/ ***************** THE END *********************/

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: