PROGRAMING PEPAR B.TECH 1ST YEAR AKTU 2018-2019
============================================================================
Q 1. Attempt all question given below: Marks: 5*1=5
A) What is difference between break and continue statement?
Ans:- The break statement: the break statement allows to terminate the execution of the loop and to
jump out of the loop. When we want to jump out of a loop instantly, without waiting to get back to the
conditional test, the keyword break allows us to do this.
void main()
{
int i;
for (i=0;i<100;i++)
{
printf(“%d”,i);
if(i==10)
break;
}takes control here
printf(“out of loop”);
}
The continue statement: The continue statements tells the compiler ‘skip ‘the following statements
and continue with the next iteration. For example:
void main()
{
int i;
for(i=1;i<=100;i++)
{
if(i%2==0) takes control here
continue;
else
printf(“%d”,i);
}
getch();
}
=========================================================================
B) What is identifier? What are the rules for identifiers (variables)?
Ans:-Identifiers are the names that are given to various program elements such as variables, symbolic
constants and functions and array. Basically identifiers are the sequences of alphabets or digits.
Rules for forming identifier name
1. Identifier name must be a sequence of letter and digits, and must begin with a letter.
2. The underscore character (‘_’) is considered as letter.
3. Names shouldn't be a keyword (such as int , float, if ,break, for etc)
4. Both upper-case letter and lower-case letter characters are allowed. However, they're not
interchangeable.
5. No special characters, such as seminon, period, blank space, slash or comma are permitted.
6. Must not contain whitespace.
C) char a[20]=”Hello”;
char b[20]=”India”;
strcat(a,b);
strcpy(b,a);
strcat(a,b);
puts(a);
puts(b);
What will be the output?
Ans:- HelloIndiaHelloIndia
HelloIndia
D) What is structure and how it is declared? What is difference between array and structure?
Ans:- Structure-structure is a user defined data type .it is used to pack the data of different types in a
group to make logically related group. General format for defining the structure is:
Structstructure name
{
Data-type of member1 member1-name ;
Data-type of member2 member2-name ;
.
.
.
Data-type of member-n member-n-name ;
};
E) What are the escape sequence characters?
Ans:-C supports some special escape sequence characters that are used to do special tasks.
Some of the escape sequence characters are as follow:
Character Constant Meaning
\n New line (Line break)
\b Backspace
\t Horizontal Tab
\f Form feed
\a Alert (alerts a bell)
\r Carriage Return
Section – B
Q 2. Attempt any five questions given below. Marks: 5*3= 15
A) WAP to print the pattern:-
*
***
*****
*******
*********
Ans:- #include <stdio.h>
int main()
{
int j, i, k;
for (i= 1;i <= 5; i++)
{
for (j= 5; j >= i; j--)
printf(" ");
for (k = 1; k <= 2 *i - 1; k++)
printf("*");
printf("\n");
}
B) WAP to find out sum of major and minor diagonal elements separately in matrix having order m*n?
ANS:- void main()
{
int a[10][10], i, j,m,n,sum=0,sum1=0;
clrscr();
printf(“enter the order of matrix\n”);
scanf(“%d%d”,&m,&n);
printf("\n\t enter matrix :\n ");
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
scanf("%d",&a[i][j]);
}
}
if(m==n)
{
for(i=0; i<m; i++)
{
for(j=0; j<n; j++)
{
if(i==j)
sum=sum + a[i][j];
if(i+j==m-1)
sum1=sum1 + a[i][j];
}
}
}
printf(“sum of diagonal elements is : %d”, sum);
printf(“sum of diagonal elements is : %d”, sum1);
getch();
}
C) WAP to print Fibonacci series up to n terms?
ANS:-void main()
{
int i,a[100],n;
printf(“enter the value of n”);
scanf(“%d”,&n);
a[0]=0;
a[1]=1;
for(i=2;i<=n-1;i++)
{
a[i]=a[i-1]+a[i-2];
}
for(i=0;i<=n-1;i++)
{
printf(“%d “,a[i]);
}
getch();
}
D) WAP for linear search in list of n elements?
ANS:- void main()
{
int a[100],n,i,item,loc=-1;
clrscr();
printf("enter the number of elements");
scanf("%d",&n);
printf("enter the numbers:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the item to be searched");
scanf("%d",&item);
for(i=0;i<n;i++)
{
if(item==a[i])
{
loc=i;
break;
}
}
if(loc>=0)
printf("element is found in position%d %d",i+1,item);
else
printf("element is not found");
getch();
}
E) WAP to count the total number of words and spaces in given string?
#include<stdio.h>
#include<conio.h>
void main()
{
char str[50];
int i,count;
count=0;
printf("Enter a string : ");
gets(str);
count=0;
for(i=0;str[i]!=’\0’;i++)
{
if(str[i]==' ' )
count++;
}
printf("The total nos of space= %d \n no of words=%d ",count, count+1);
getch();
}
F) WAP to convert capital letter into small letter and vice-versa using function?
Ans:- #include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{
char a,b;
printf(“\nenter character\n”);
scanf(“%c”,&a);
if(islower(a))
b=toupper(a);
else
b=tolower(a);
printf(“%c”,b);
getch();
}
Section - C
Q 3 . Attempt any two questions given below. Marks: 2*5=10
A) Create a structure having name student having members name, age and city. WAP to print the
details for students whose city is entered by user among n students?
Ans:- struct student
{
int age;
char name[50], city[50];
} s[100];
void main()
{
int i , n;
char dcity[90];
printf(“enter the no of students :”);
scanf(“%d”,&n);
printf("enter the records of student name ,city and age\n :");
for(i=0 ; i<n ; i++)
{
scanf("%s%s%d",&s[i].name,s[i].city,s[i].age);
}
printf(“\nenter desired city\n”);
scanf(“%s”,dcity);
printf(“record of the student are :\n”);
printf(“name\tcity\tage\n”);
for(i=0;i<n;i++)
{
if(strcmp(s[i].city,dcity)==0)
printf("%s\t%s\t%d\n",s[i].name,s[i].city,s[i].age);
}
getch();
}
B) WAP to print all the prime numbers stored in an array having 10 elements? Design flow chart of the
pattern given below:
1
12
123
1234
12345
ANS:- void main()
{
int i,j ,c=0,a[10];
printf(“enter the numbers of array\n”);
for(i=0;i<=n-1;i++)
{
scanf(“%d”,&a[i]);
}
for(j=0;j<=9;j++)
{
c=0;
for(i=2;i<=a[j]-1;i++)
{
if(a[j]%i==0)
c++;
}
if(c==0)
printf(“%d\n”,a[j]);
}
getch();
}
C) WAP to check the given matrix is identity or not having order m*n? What is data type? Define
format specifier, range and size of primary data types
ANS:- #include <stdio.h>
void main()
{
int a[10][10];
int i, j, m, n, flag = 1;
printf("Enter the order of the matrix A \n");
scanf("%d %d", &m, &n);
printf("Enter the elements of matrix A \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
}
}
printf("MATRIX A is \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("%3d", a[i][j]);
}
printf("\n");
}
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
if (a[i][j] != 1 && a[j][i] != 0)
{
flag = 0;
break;
}
}
}
if (flag == 1 )
printf("It is identity matrix \n");
else
printf("It is not a identity matrix \n");
}
C language is rich in its data types. C supports following classes of data types.
1. Primary/Fundamental data types
2. Derived data types/composite data types
Size and range of data types
Data types Range Bytes format
Signed char -128 to 127 1 %c
Unsigned char 0 to 255 1 %c
Short signed int -32768 to32767 2 %hd
Short unsigned int 0 to 65535 2 %hu
signed int -32768 to32767 2 %d
unsigned int 0 to 65535 2 %u
long signed int -2147483648 to
+2147483648
4 %ld
long unsigned int 0 to 4294967295 4 %lu
float -3.4E38 to +3.4E38 4 %f
double -1.7E308 to +1.7E308 8 %lf
long double -1.7E4932 to +1.1E4932 10 %Lf
Comments
Post a Comment