0% found this document useful (0 votes)
969 views19 pages

Srikanth External Lab Answers

The document contains 20 programming tasks ranging from basic tasks like finding the minimum number of notes to form an amount, to more complex tasks like sorting a list of schools based on student count then teacher count, transposing a matrix using pointers, and calculating word frequencies in a string. Many tasks involve reading input, processing arrays or strings using loops, and outputting the results. Sample inputs and outputs are provided for each task to illustrate the expected behavior.

Uploaded by

Kumar Naidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
969 views19 pages

Srikanth External Lab Answers

The document contains 20 programming tasks ranging from basic tasks like finding the minimum number of notes to form an amount, to more complex tasks like sorting a list of schools based on student count then teacher count, transposing a matrix using pointers, and calculating word frequencies in a string. Many tasks involve reading input, processing arrays or strings using loops, and outputting the results. Sample inputs and outputs are provided for each task to illustrate the expected behavior.

Uploaded by

Kumar Naidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 19

1.

Task Description:

A and B are two friends fond of playing mathematical games. One day they both decided to
play a game. A has to calculate the minimum number of notes required to form the given
amount using the denomination(500,100,50,20,10,5,2,1).

Sample Input:
575

Sample Output:

2. Task Description:

Write a C program to find whether the given number is armstrong or not

Sample Input:

Sample Output:

Yes

3. Task Description:

Given an Integer X.Find the sin and cosine value of x using Series Expansion.

Sample Input:

78

Sample Output:

0.978141 0.207745

4. Problem Description:
Count the No of primes between two given Integers.

Sample Input:

1 10

Sample Output:

5. Task Description:
Niharika is a scientist and she has designed a robo. The function of Robo is just to walk
forward and backward continuously. One day Niharika went out of the lab and one of the kids
has taken the robo and started observing how it is walking. But there is a ditch on the
forward end and backward which was not observed by the kid. So now we have to check
whether the robo falls in a ditch or not. If it falls, whether it is the forward ditch or backward
ditch and time to fall in a ditch

Input Format:

5 integers denoting no.of forward steps, no.of backward steps, forward ditch position,
backward ditch position, and time taken for single step

Output Format:

No if the robo does not falls in ditch.

F integer. F denotes forward ditch and integer is the time taken by robo to fall in a ditch

B integer. B denotes backward ditch and integer is the time taken by robo to fall in a ditch

Sample Input:

13315

Sample Output:

B 15

6. Task Description:

Find the roots of a quadratic equation.

Input Format:

First line l contains a,b and c, separated by space, where a is the coefficient of x^2 term, b is
the coefficient of x and c is constant .

Output Format:

Print the nature of the roots and roots of the quadratic equation.

Sample Input:

140

Sample Output:

Roots are real numbers.

Roots of quadratic equation are:0.000 , -4.000


7. Task Description:

Multiplication of matrices using pointers.

#include<stdio.h>

#include<stdlib.h>

int main()

int i,j,k,l,n;

int **a,**b,**c;

printf("enter the order of matrix(n*n)");

scanf("%d",&n);

a=(int**)malloc(sizeof(int*)*n);

b=(int**)malloc(sizeof(int*)*n);

c=(int**)malloc(sizeof(int*)*n);

for(i=0;i<n;i++)

a[i]=(int*)malloc(sizeof(int)*n);

b[i]=(int*)malloc(sizeof(int)*n);

c[i]=(int*)malloc(sizeof(int)*n);

for(i=0;i<n;i++)

for(j=0;j<n;j++)

{
scanf("%d",&a[i][j]);

for(i=0;i<n;i++)

for(j=0;j<n;j++)

scanf("%d",&b[i][j]);

for(i=0;i<n;i++)

for(j=0;j<n;j++)

k=0;

for(l=0;l<n;l++)

k=k+(a[i][l]*b[l][j]);

c[i][j]=k;

for(i=0;i<n;i++)
{

for(j=0;j<n;j++)

printf(" %d",c[i][j]);

printf("\n");

8. Task Description:

Given an integer N representing a number in decimal format. There are two types of queries:

Type 0 :Print the Binary representation of N

Type 1:Print the Hexa-decimal representation of N

Input Format:

Single Integer N denoting the number in Decimal format and a value X representing type of
query(0 or 1).

Output Format:

Single line containing the number in required format. Print 8 bit binary number .

Sample Input:

00

Sample Output:

0000

9. Task Description:

Print the most frequent number in the array.

Sample Input

8
13379246

Sample Output:

#include<stdio.h>

int main()

int n;

scanf("%d",&n);

int arr[n];

int i,j,count=0;

for(i=0;i<n;i++)

scanf("%d",&arr[i]);

int max=0;

int maxpos;

for(i=0;i<n;i++)

count=0;

for(j=0;j<n;j++)

if(arr[i]==arr[j])

count++;
}

if(count>max)

max=count;

maxpos=i;

printf("%d",arr[maxpos]);

10. Task Description:

Print sum of the largest two numbers in an array.

Sample Input:

1 -1 2 3

Sample Output:

23

sum=5

program:

#include<stdio.h>

int main()

int n;

scanf("%d",&n);

int arr[n];
int i,j,sum=0;

for(i=0;i<n;i++)

scanf("%d",&arr[i]);

int max=0;

int in1,in2;

for(i=0;i<n;i++)

sum=0;

for(j=0;j<n;j++)

if(i!=j)

sum=arr[i]+arr[j];

if(sum>max)

max=sum;

in1=i;

in2=j;

}
}

printf("%d %d",arr[in1],arr[in2]);

11. Task Description:

You will be given a string and you need to say how strong it is as a password. conditions are
as follows

1. Strong, when there is at least one numeric, at least one in upper and one in lower
case letter, and a special character.

2. If anyone of those is missing it is a Good password.

3. If any 2 are missing it is an Ok password

4. If any 3 are missing it is a Weak password

*Output strings are case sensitive.

Input Format:

password

Output Format:

The strength of password

Sample Input:

aK1@m

Sample Output:

Strong

12. Task Description:

Print the number which repeats ,odd number of times in an array.


Sample Input:

12123

Sample Output:
3

#include<stdio.h>

int main()

int n;

scanf("%d",&n);

int arr[n];

int i,j,odd;

for(i=0;i<n;i++)

scanf("%d",&arr[i]);

odd=arr[0];

for(i=1;i<n;i++)

odd=(odd^arr[i]);

printf("%d",odd);

13. Task Description:

Interchange the positions of max and min in an array.l

Sample Input:

35784
Sample Output:

85734

#include<stdio.h>

int main()

int n;

int i,j;

int maxpos,minpos;

scanf("%d",&n);

int arr[n];

for(i=0;i<n;i++)

scanf("%d",&arr[i]);

int max=0;

int min=1000000;

for(i=0;i<n;i++)

if(arr[i]>max)

max=arr[i];

maxpos=i;

if(arr[i]<min)

{
min=arr[i];

minpos=i;

arr[minpos]=max;

arr[maxpos]=min;

for(i=0;i<n;i++)

printf("%d ",arr[i]);

14. Task Description:

Sort the students in a given class based on their roll nos.

Student details contains name and roll no.

Sample Input:

avi

kavi

Ravi

Sample Output:

ravi 1

avi 2

Kavi 3
15. Task Description:

Removing Sub string from a given string.


Input Format:

First line contains N, denoting string size. Next line contains a string S. Next line contains
integer variable P, from where n characters starting from that position are to be deleted. Next
line contains a integer variable n, denoting number of characters that are to be delated(i.e,
length of sub string).

Output Format:

Print the string after replacement.

Sample Input:

10

HelloWorld

Sample Output:

Hello

16. Task Description:

Printing Floyd’s Triangle pattern using recursion.

Sample Input :

Sample Output :

##

###

17. Task Description:


Nth Term of a Fibonacci series using recursion.

Sample Input:

36

Sample Output:
14930352

18. Task Description:

You will be given no.of students and number of teachers count of all the schools in the city.
You have to sort (Ascending Order) the list based on the number of students. If a tie occurs
then you have to check for the number of teachers

Input Format:

First line contains "n" value. followed by no.of students and number of teachers separated by
a space. Each school data will be present in the new line.

Output Format:

Print the sorted list in ascending order

Sample Input:

10 2

98

10 4

12 1

67

Sample Output:

67

98

10 2

10 4

12 1

19. Task description


Transpose of a given matrix using pointers.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int **a;
int **b;
int i,j,r,c;
printf("enter the rows and columns");
scanf("%d%d",&r,&c);
a=(int**)malloc(sizeof(int*)*r);
b=(int**)malloc(sizeof(int*)*c);
for(i=0;i<r;i++)
{
a[i]=(int*)malloc(sizeof(int)*c);
}
for(i=0;i<c;i++)
{
b[i]=(int*)malloc(sizeof(int)*r);
}
printf("enter the matrix");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
b[j][i]=a[i][j];
}
}

for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
{
printf(" %d",b[i][j]);
}
printf("\n");
}}
20. Task description
Calculate the frequency of a word in a given paragraph/string.(hint : Use string.h
functions)

21. Task description.


Implement strcat().
#include<stdio.h>
int main()
{
char s1[200],s2[100];
int i,j,k,n,m;
printf("enter string 1\n");
scanf("%s",s1);
printf("enter string 2\n");
scanf("%s",s2);
for(m=0;s1[m]!='\0';m++);
for(n=0;s2[n]!='\0';n++);
for(i=m,j=0;i<m+n;i++,j++)
{
s1[i]=s2[j];
}
printf("%s",s1);
}

22. Task description.


Count the number of words in a file.(use ispunct in ctype.h for punctuations).
#include<stdio.h>
#include<string.h>
int main()
{
char para[200];
printf("enter the paragraph\n");
gets(para);
int c=0,i;
if((para[0]>=32&&para[0]<=47)||(para[0]>=58&&para[0]<=64))
{
c=-1;
}
for(i=0;i<strlen(para);i++)
{

if((para[i]>=32&&para[i]<=47)||(para[i]>=58&&para[i]<=64))
{
c++;
}
while((para[i]>=32&&para[i]<=47)||(para[i]>=58&&para[i]<=64))
{
i++;
}
}
printf("%d",c);
}

23. Task description.


Count the number of occurrences of a character in a file.

24. Task description.


Given N Student records {name ,roll no,marks}.
Sort the students based on their marks.

#include<stdio.h>
#include<string.h>
typedef struct student
{
char name[100];
int roll;
int marks;
}st;
int main()
{
int n,i,j;
printf("enter number of students\n");
scanf("%d",&n);
st s[n],temp;
printf("enter student details\n");
for(i=0;i<n;i++)
{
scanf("%s%d%d",s[i].name,&s[i].roll,&s[i].marks);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
{
if(s[j+1].marks<s[j].marks)
{
temp=s[j+1];
s[j+1]=s[j];
s[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%s %d %d",s[i].name,s[i].roll,s[i].marks);
printf("\n");
}
}

25. Task description.


Given N Student records {name ,roll no,marks}.
Sort based on names.

#include<stdio.h>
#include<string.h>

typedef struct student

char name[100];

int roll;

int marks;

}st;

int main()

int n,i,j;

printf("enter number of students\n");

scanf("%d",&n);

st s[n],temp;

printf("enter student details\n");

for(i=0;i<n;i++)

scanf("%s%d%d",s[i].name,&s[i].roll,&s[i].marks);
}

for(i=0;i<n-1;i++)

for(j=0;j<n-1;j++)

if(strcmp(s[j+1].name,s[j].name)<0)

temp=s[j+1];

s[j+1]=s[j];

s[j]=temp;

for(i=0;i<n;i++)

printf("%s %d %d",s[i].name,s[i].roll,s[i].marks);

printf("\n");

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy