Accenture Problems
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 ()
int n, c, sum;
int a[1000];
{
sum = sum + a[i];
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");
}