0% found this document useful (0 votes)
20 views8 pages

Accenture Problems

The document contains solutions to 5 programming problems: 1) Find the sum of leaders in an array 2) Calculate average of numbers divisible by 3 and even 3) Convert a decimal number to a given base 4) Change first letter of each word to uppercase 5) Check password strength based on various conditions.

Uploaded by

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

Accenture Problems

The document contains solutions to 5 programming problems: 1) Find the sum of leaders in an array 2) Calculate average of numbers divisible by 3 and even 3) Convert a decimal number to a given base 4) Change first letter of each word to uppercase 5) Check password strength based on various conditions.

Uploaded by

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

ACCENTURE PROBLEMS

1.Write a program to print the sum of all the LEADERS in the array.
An element is a leader if it is greater than all the elements to its right
side. And the rightmost element is always a leader.
SAMPLE INPUT :
7
52 66 64 36 45 24 32
SAMPLE OUTPUT:
207
SOLUTION :

#include<stdio.h>
int main ()
{
int n;
scanf ("%d", &n);
int a[100];
int s = 0;
int r;
for (int i = 0; i < n; i++)
scanf ("%d", &a[i]);
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n + 1; j++)
{
if (a[i] >= a[j])
{
r = 1;
continue;
}
else
{
r = 0;
break;
}
}
if (r == 1)
s = s + a[i];
}
printf ("%d", s);
return 0;
}
2. Calculate the average of numbers divisible by 3 and even at the
same time
You have been given an array nums and N, where nums is the
array and n will be its size. Return the average of the number divisible
by 3 and should be even.
Input- An array of nums with size N has been given
Output- A single digit number should be return whicho is the
average of all the required number.

SOLUTION:

#include <stdio.h>

int main ()

printf (" ");

int n, c, sum;

scanf ("%d", &n);

int a[1000];

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

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

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

if (a[i] % 6 == 0 && a[i] > 0)

{
sum = sum + a[i];

c++;

printf ("%d", sum / c);

return 0;
}

3.DECIMAL TO N BASE:
SAMPLE INPUT:
718
12
SAMPLE OUTPUT:
4BA

SOLUTION :
#include <stdio.h>
intmain ()
{
int num, n, rem;
char a[100];
int c = 0;
scanf ("%d %d", &num, &n);
while (num > 0)
{
rem = num % n;
if (rem >= 0 && rem <= 9)
{
a[c++] = rem + 48;
}
else
{
a[c++] = ((rem % 10) + 65);

}
num /= n;
}
for (int i = c; i >= 0; i--)
printf ("%c", a[i]);
}
4.EACH WORD FIRST LETTER WILL BE CHANGED TO
UPPER CASE:
SAMPLE INPUT:
one two three
SAMPLE OUTPUT:
One Two Three

SOLUTION:

#include <stdio.h>
int main ()
{
char s[100];
scanf ("%[^\n]s", s);
int len = 0;
for (int i = 0; s[i]; i++)
{
if (i == 0)
s[i] = s[i] - 32;
else if (s[i] == 32)
s[i + 1] = s[i + 1] - 32;
}
printf ("%s", s);
}
5.PASSWORD CHECK
SAMPLE INPUT:
Accenture@123
SAMPLE OUTPUT:
STRONG PASS

CONDITIONS:
1.Length should be greater than 8.
2. Atleast one uppercase is mandatory.
3.Atleast one number is mandatory.
4.Atleast one special character is mandatory.

SOLUTIONS :
#include <stdio.h>
#include<string.h>
int main()
{
char s[100];
scanf("%[^\n]s",s);
int v=0,l=0,u=0,n=0,sp=0;
int len=strlen(s);
for(int i=0;s[i];i++){
if(s[i]>='a'&& s[i]<='z' )
l++;
else if(s[i]>='A'&& s[i]<='Z' )
u++;
else if(s[i]>='0'&& s[i]<='9')
n++;
else
sp++;
}
if(len>=8 && u>=1 && n>=1 && sp>=1)
printf("\nSTRONG PASS");
else
printf("\nNOT STRONG");
}

You might also like