Professional Documents
Culture Documents
Group No 1
Course Instructor : Ms. Richa Malhotra ______________ Course Tutor (if applicable) : _____________
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s work or
from any other source except where due acknowledgment is made explicitly in the text, nor has any part
been written for me by another person.
Evaluator’s comments:
_____________________________________________________________________
1|Page
E3004A07
Group No 1
Home Work 1
CAP101
Part A
1. Explain the difference between associativity and precedence with the help
of an example?
2|Page
E3004A07
Group No 1
<Operator: = >
3|Page
E3004A07
Group No 1
Ans.
output: output:
y=4 x=6 a=10 y=5 x=6 a=8
Ans.
4|Page
E3004A07
Group No 1
Ans.
5|Page
E3004A07
Group No 1
Ans.
Ans.
6|Page
E3004A07
Group No 1
unsigned integer
PART B
4. Write a program that will examine each character in a character type array
and write the ASCII equivalent of each character. Size of the array is known
in advance by the integer variable n.
Ans.
#include<conio.h>
#include<stdio.h>
void main()
{
char a[10];
int i; clrscr();
printf("Enter the string: ");
gets(a);
for(i=0;a[i]!='\0';i++)
{
printf("%c= %d",a[i],a[i]);
printf("\n");
}
getch();
}
5. Write a program to display the day of week according to the day no. entered
by the user.
7|Page
E3004A07
Group No 1
Ans.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("\nEnter the day number of the week:");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nDay is Monday");
break;
case 2:
printf("\nDay is Tuesday");
break;
case 3:
printf("\nDay is Wednesday");
break;
case 4:
printf("\nDay is Thursday");
break;
case 5:
printf("\nDay is Friday");
break;
case 6:
printf("\nDay is Saturday");
break;
case 7:
printf("\nDay is Sunday");
break;
default:
printf("\nInvalid Choice");
}
getch();
}
8|Page
E3004A07
Group No 1
6. Write a program that receives a multi-word string and prints it in the form
of one word per line.
Ans.
#include<conio.h>
#include<stdio.h>
void main()
{
char a[30];
int i;
clrscr();
printf("Enter the string: ");
gets(a );
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ')
printf("\n");
else
printf("%c",a[i]);
}
getch();
}
************
9|Page