Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double ratio(char arr[])
- {
- int b=0,c=0;
- double ratio;
- for(int i=0;i<100;i++)
- {
- if(arr[i]=='c')
- c++;
- else if(arr[i]=='b')
- b++;
- }
- if(c==0)
- return -1;
- else
- ratio=(double)b/c;
- return ratio;
- }
- int main()
- {
- char DNA[100];
- printf("Input: ");
- gets(DNA);
- double result=ratio(DNA);
- if(result==-1)
- {
- printf("All characters are 'b'");
- return 0;
- }
- else
- printf("Ration of 'b' to 'c' is: %.3lf", result);
- return 0;
- }
- &&
- #include <stdio.h>
- void ratio(char str[])
- {
- int count1 = 0, count2 = 0, x, y;
- for (int i = 0; i < 100; i++)
- {
- if (str[i] == 'b')
- {
- count1++;
- }
- }
- for (int i = 0; i < 100; i++)
- {
- if (str[i] == 'c')
- {
- count2++;
- }
- }
- float r;
- r = count1 / count2;
- printf("Ratio b and c is %d : %d or %.2f", count1, count2, r);
- }
- int main()
- {
- char DNA[100];
- printf("Enter random numbers of b and c:\n");
- scanf("%s", DNA);
- ratio(DNA);
- return 0;
- }
Add Comment
Please, Sign In to add comment