Ada Programs-Shreyas
Ada Programs-Shreyas
Write a function to solve the following equation a3 + a2b + 2a2b + 2ab2 + ab2 + b3
Write a program to accept three values in order of a, b and c and get the result of the above equation.
solution->
#include <stdio.h>
int main() {
int a, b, c;
int result;
// Input values
// Compute (a + b)^3
result = (a + b) * (a + b) * (a + b);
return 0;}
Q2. You have write a function that accepts, a string which length is “len”, the string has some “#”, in it
you have to move all the hashes to the front of the string and return the whole string back and print
it
Example :-
Input:
Move#Hash#to#Front
Output:
###MoveHashtoFront
solution->
#include <stdio.h>
#include <string.h>
int i, j = 0;
char temp[100];
if (str[i] != '#') {
temp[j++] = str[i];
}
// Fill the original string with #s at the beginning
str[i] = '#';
str[i++] = temp[k];
int main() {
char str[100] ;
scanf(“%s”,str);
moveHashToFront(str);
return 0;
}
Q3.Written test have a coding question, wherein the students are given a string with multiple characters
that are repeated consecutively. You’re supposed to reduce the size of this string using mathematical
Input :
aabbbbeeeeffggg
Output:
a2b4e4f2g3
Input :
abbccccc
Output:
ab2c5
solution->
#include <stdio.h>
int i = 0, count;
printf("%c", str[i]);
count = 1;
count++;
i++;
if (count > 1) {
printf("%d", count);
i++;
printf("\n");
int main() {
char input[10] ;
scanf("%s",input);
compress(input);
return 0;
}
Q.4: Consider a string, S, that is a series of characters, each followed by its frequency as an integer. The
string is not compressed correctly, so there may be multiple occurrences of the same character. A
properly compressed string will consist of one instance of each character in alphabetical order followed
Input: "a3b5c2a2"
Output: "aaabbbbbcc"
solution->
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int i = 0;
if (isalpha(str[i])) {
char ch = str[i];
i++;
int num = 0;
while (isdigit(str[i])) {
i++;
printf("\n");
int main() {
char input[] ;
scanf("%s",input);
expandString(input);
return 0;