You are on page 1of 10

Given the string WORD POCESSING Write a program to read the

string from the terminal and display the same in the following format?

1. WORD PROCESSING
2. WORD
PROCESSING
3. W.P
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j=0;
char a[50];
clrscr();
printf("write word processing\n\n");
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();
}

Output
write word processing

WORD PROCESSING

1.

WORD

2.

WORD

PROCESSING

PROCESSING

3.

W.P.

3. Write a program to read and display the following


table of data:
NAME
Fan
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[30],b1[10];
int e1,i,j=0,k;
float f1;

CODE
67831

PRICE
1234.59

clrscr();
printf("enter header row\n");
for(i=0;i<=30;i++)
{
scanf("%c",&a[i]);
{
if(a[i]=='\n')
goto label;
}
j++;
}
label:
printf("enter row data\n");
scanf("%s%d%f",&b1,&e1,&f1);
printf("\n");
for(i=0;i<=j;i++)
{
printf("%c",a[i]);
if(a[i]==' ')
printf("\t");
}
printf("\n");
{
printf("\n%s\t%d\t%f",b1,e1,f1);
}

getch();
}

Output
enter header row
name code price
enter row data
Fan 67831 1234.56789

name

Fan

code

2295

price

1234.567871

Part-B

Q4. Write a program to display the day of week


according to the day no. entered by the user.
Ans:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i;

clrscr();
printf("enter day no");
scanf("%d",&i);
switch(i)
{
case 1:
printf("sunday");
break;
case 2:
printf("monday");
break;
case 3:
printf("tuesday");
break;
case 41:
printf("wednesday");
break;
case 5:
printf("thrusday");
break;
case 6:
printf("friday");
break;
case 7:
printf("saturday");

break;
default:
printf("wrong numer");
}
getch();
}

output

enter day no1


sunday

Q5. Write a program that receives a multi-word string


and prints it in the form of one word per line.
Ans:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j=0;
char a[100];

clrscr();
printf("\n\t\tenter a multi-word string\n");
for(i=0;i<100;i++)
{
scanf("%c",&a[i]);
j=j++;
if(a[i]=='\n')
break;
}
printf("\n\t\tstring in the form of one word per line\n");
for(i=0;i<j;i++)
{
printf("%c",a[i]);
if(a[i]==' ')
printf("\n");
}
getch();
}

Output

enter a multi-word string


hi my name is varun. i am doing mca from lpu.

string in the form of one word per line


hi
my
name
is
varun.
i
am
doing
mca
from
lpu.
6th ANS:
(a) 78 b 45
Scanf(%d%c%d,&a,&b,&c);
Printf(%d%d%d,a,b,c);
(b) 123 1.23 45a
Scanf(%d%f%s,&x,&y,&z);
Printf(%d%f% %s,x,y,z);
(c) 15-10-2008
Printf(enter the date, month and year);
Scanf(%d%d%d,&date,&month,&year);
Printf(%d-%d-%d,date,month,year);
(d) 10 TRUE 20

Scanf(%d%s%d,&p,&q,&r);
Printf(%d%s%d,p,q,r);

You might also like