USING OF BREAK AND SWITCH;

QUESTION- ENTER STRING CONTAINING 0 AND 1 AND CHECK THE NO. OF SAME, ALSO CHECK THE NO. OF STRINGS;

ANSWER;

#include<stdio.h>
#include<conio.h>
int main()
{
    int a=0,b=0,d=0,x=0;
    char c[50];
    printf(“Enter the string containg 1 and 0: “);
    gets(c);
    while(c[x]!=”)
    {    switch(c[x])
        {
        case ‘1’:
        a++;
        break;
        case ‘0’:
        b++;
        break;  //IF here we dnt write break; then it will execute every case and program will give an error
        default:
        d++;
        break;
        }
    x++;
    }
    printf(“\nNo. of 1 = %d , No. of 0. = %d , No. of strings = %d”,a,b,d);
    printf(“\n\n\tPROGRAMMING @ CODE STUDIO”);
    getch();
}

OUTPUT;

break

POPULATION;

QUESTION-

The population of country X is increasing at an average rate of r1 percent a year and that of country Y is increasing at an average rate of r2 percent a year. Find the number of months by which the population of country X would become greater than the population of country Y.

ANSWER-

#include<stdio.h>
#include<conio.h>
int main()
{
int p1,p2;
int r1,r2,i=0;
printf(“\nINPUT POPULATION OF 1ST COUNTRY:”);
scanf(“%d”,&p1);
printf(“\nINCREAMENT RATE PERCENTAGE:”);
scanf(“%d”,&r1);
printf(“\nINPUT POPULATION OF 2ND COUNTRY:”);
scanf(“%d”,&p2);
printf(“\nINCREAMENT RATE PERCENTAGE:”);
scanf(“%d”,&r2);
while(p1<=p2)
{
p1=p1+(p1*r1/100);
p2=p2+(p2*r2/100);
i++;
}
printf(“\nTOTAL YEAR AFTER WHICH THE POPULATION BECOME EQUAL:%d”,i);
printf(“\n\nPROGRAMMING @ CODE STUDIO”);
getch();
}

OUTPUT-

pop