[go: up one dir, main page]

0% found this document useful (0 votes)
56 views6 pages

Problems

The document contains 7 problem descriptions related to programming concepts like functions, arrays, strings, recursion, and pointers. For each problem, sample code is provided as the solution using the specified concept. The problems cover topics like parameter passing, string manipulation, sorting arrays, Fibonacci series, and summing array elements recursively.

Uploaded by

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

Problems

The document contains 7 problem descriptions related to programming concepts like functions, arrays, strings, recursion, and pointers. For each problem, sample code is provided as the solution using the specified concept. The problems cover topics like parameter passing, string manipulation, sorting arrays, Fibonacci series, and summing array elements recursively.

Uploaded by

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

Problem description:

1. Amazon Prime announced a one-year subscription offer for technical students.


we will provide two numbers for the addition that must be use call by reference.
If the answer is correct for this question, you will get the offer. Can you complete
the task to win this competition?(using function)
Ans:
#include <stdio.h>
int addTwoNumbers(int *n1,int *n2)
{
return 0;
}
int main()
{
int *ptr ,*qtr, first, second;
scanf("%i %i", &first, &second);
ptr = &first;
qtr = &second;
int sum = *ptr + *qtr;
printf("%i", sum);
addTwoNumbers(ptr,qtr);
return 0;
}
O/P:
5 6
11
2. Arif and Selvan both are friends. Both are planning to utilize the vacation
holidays by learning a programming language. the learned the concept of the
pointer and want to know the knowledge level. So they decided to make a coding
test for each other. Arif wrote a name ending with numbers in the paper.Selvan
wants to identify the total length of the input. Can you help Selvan?(using
function)
Ans:
#include <stdio.h>
#include <string.h>
int calculateLength(char* ch)
{
int i=0;
i++;
ch++;
return i;
}
int main()
{
char a[151];
scanf("%s",a);
int l=strlen(a);
printf("%d",l);
return 0;
}
Input:
Hello
Output:
4
3. Yasir was traveling from Chennai to Bangalore by bus. He looking the LED
display board for the destination place name on the bus. But it shows the
reflection of the destination place name in reverse. can you write the code to
change the display in reverse order?(using string function)
Ans:
#include <stdio.h>
#include <string.h>
int main()
{
int i ;
char s[30];
gets(s, 30);
for(i=strlen(s)-1; i >=0 ; i --)
printf("%c", s[i]);
return 0;
}
Input
Tcrsk
Output
Ksrct

4. Nancy, Simon, and Swati were all attending campus interviews. they got selected
for the second round. Nancy failed to clear the second round and others to
selected for the next round of interviews.Nancy discussed with her friend the
question which came in the interview.one of the questions was, to create a
program for the Fibonacci series. Nanc e doesn't know, how to solveit.But it's in
the syllabus of his exam. So can you help to create a program in the specified
concept to get an offer in the next interview ?.(using recursion)

Ans:

#include <stdio.h>
int fibonacci(int num)
{
if (num == 0)
{
return 0;
}
else if (num == 1)
{
return 1;
}
else
{
return fibonacci(num - 1) + fibonacci(num - 2);
}
}
int main()
{
int num;
scanf("%d", &num);
for (int i = 0; i < num; i++)
{
printf("%d, ", fibonacci(i));
}

return 0;
}
Input
5
Output
0, 1, 1, 2, 3,

5. Yasir is a very active young man who is very interested in making money in a
simple way. So he is always looking for a way to make some money. One day, a
money-making show called Jackpot on popular channel news came to Yasir's
ears. So he was going to the JACKPOT game in a game park it has a dial full of
numbers in random order. If it is arranged in ascending order using function ,
he will win a million-dollar prize. can you help him to input an array of size n
and sort it in ascending order?
Ans:
#include<stdio.h>
void asc(int a[100],int n)
{
int i,j,temp;
for(i=0; i<n-1; i++)
{
for(j=0; j<n-i-1; j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
int main()
{
int a[100],i,n;
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
asc(a,n);
for(i=0; i<n; i++)
{
printf("%d ",a[i]);
}
return 0;
}
Input:
5

6
3
5
6
2
1
Output:
12566
6. Sajid is an eighth-grader in a CBSE school. Although he scored well in many
subjects, he did not an expert in computer programming languages. But Sajid's
computer examination is scheduled for next week. As per the blueprint, many
questions would come from the recursive function topic. He collected previous
year's questions. one of the repeated questions is to calculate the factorial value
for the given number using a recursive function. Can you help him to calculate
the factorial using recursion?

Ans:
#include <stdio.h>
long facto(int n)
{ if (n>=1) return n*facto(n-1); else
return 1;
}
int main()
{
int q;
scanf("%d",&q);
printf("%ld", facto(q));
return 0;
}
Input:
5
Output:
120

7. Tina is a Bachelor of Computer Applications (BCA) student. During her final


year Campus Interview, she has an opportunity to get a job in a software
company in Bangalore. The company provides Five months training period with
Rs.30000/month Package. Then it will be incremented to Rs.55000 per month. At
the end of the training, the examination was conducted for all freshers, Tina got
a question paper and one of the questions comes under the concept of
programming. The program was, she has to calculate the sum of an array of
elements using RECURSION to Complete One of Her math Problem. Tina does
not know how to get the output for this program using recursion. So you have to
help Tina get this job.

Ans:

#include <stdio.h>
int sum(int arr[],int start, int len);
int main()
{
int N,i;
scanf("%d",&N);
int arr[N];
for (i=0;i<N;i++)
scanf ("%d",&arr[i]);
int sumofarray=sum(arr,0,N);
printf("%d",sumofarray);
return 0;
}
int sum(int arr[],int start,int len)
{
int i;
for(i=0;i<len;i++)
start+=arr[i];
return start;
}
Input:
4

5
6
3
2
Output:
16

You might also like