Mcs011 1st semester Quetion Answer 2019-20
Q1.Write the following functions that:
a) Request the user for two integers and outputs them and their sum.
b) Request the user for two integers and outputs their remainder after division.
c) Request the user for two floats and outputs their product.
d) Request the user for a word and prints it twice on the same row.
Write a C (main) program to provide the above functions as options to the user using
switch statement and performs the functions accordingly.
Ans:-
#include <stdio.h> //header file it take standered input out
#include<string.h> //header file it allow string data.
#include<conio.h> //header file it take console input out
void main()//main Function
{ //program Open
int a,b,c,d; string s; //declare variable
clrscr(); //clean the console Window
printf("Select A Option To Process\n1. Sum to digit.\n2. Show Reminder of two digit.\n3. show Product of Two Value.\n4. To Twice A Word."); //print the message
scanf("%d",&d); //take input
switch(d){ //check condition
case 1:
printf("Enter Value For A");
scanf("%d",&a);
printf("Enter Value For B");
scanf("%d",&b);
c=a+b; //here a and b is sum and store in c
printf("Sum Of A And B Is %d",c); //here it print output
break; //terminate The process
case 2:
printf("Enter Value For A");
scanf("%d",&a);
printf("Enter Value For B");
scanf("%d",&b);
c=a%b;
printf("Remaider Of A And B Is %d",c);
break;
case 3:
printf("Enter Value For A");
scanf("%d",&a);
printf("Enter Value For B");
scanf("%d",&b);
c=a*b;
printf("Sum Of A And B Is %d",c);
break;
case 4:
printf("Enter A Word");
scanf(“%s”,s);
int length =strlen(s);
for(int i=0;i<length;i++){
printf(“%s %s”,s[i],s[i]);
}
break;
default: //it show at the Time of wrong option selection
printf("You Have select A Wrong Option Please Try Again");
break;
}
getch();
}
Q2.Write an algorithm, draw a corresponding flowchart and write an interactive program to
convert a binary number to its decimal equivalent.
Ans program:
#include<stdio.h>
#include<conio.h>
void main(){
int num,temp,base=1,dec=0;
print("Enter Binary Number");
scanf("%d",&num);
temp=num;
while(temp>0){
int last_digit=temp%10;
temp=temp/10;
dec+=last_digit*base;
base=base*2;
}
printf("\nDecimal number is %d",dec);
getch();
}
Algorithm:
Pseudo code
step1: Start Program
step2: Input Num
step3: Initialize dec to o and temp equal num,base to one.
step4: while num greater zero
Step5: Initialize last_digit equal remainder temp
step6: Initialize tamp equal temp divide by 10.
Step7: Initializedec Plus equal last_digit multiply by base
step8: now base equal to base multiply by 2
step9: print the dec
step10: Close The Program
Q3. Write the following functions that:
a) Request the user to input a 5 digit number and reverse the given number and print it.
b) Request the user to input two floats and outputs the largest of the inputs.
c) Request the user to input an integer and, if the number is divisible by two, divides it by
two, otherwise multiplies it by three and output the result.
d) Request the user for three integers and output whether any of them are equal. Use only
one if-else-statement
Write a C (main) program to provide the above functions as options to the user using
switch statement and perform the functions accordingly.
Ans:-
#include<stdio.h>//header file allow standered input output
#include<conio.h>//header show console i/o
void main() //main function
{//start program
int a;//declare integer
printf("Please Select An Option To Perform Task\n1.Reverse The Number\2.Check Float Numaber largest\n3.check no is divisible by two otherwise multiplies by three\n4. check whether any of them are equal or not");//print message
scanf("%d",&a);//take input
switch(a)//check condition
{
case 1:
int b,rev=0,rem;
printf("enter 5 digit number");
scanf("%d",&b);
while(b>0)
{
rem=b%10;
rev=rev*10+rem;
b=b/10;
}
printf("reversed number:%d",rev);
break;
case 2:
float b,c;
printf("enter 1st float value");
scanf("%f",&b);
printf("enter 2nd float value");
scanf("%f",&c);
if(b>c)
{
printf("%f is Largest",b);
}
else if(b<c){
printf("%f is largest",c);
}else{
printf("Both Are Equal");
}
break;
case 3:
int b;
float c;
printf("enter A number");
scanf("%d",&b);
if(b%2==0){
c=b/2;
printf("output is %d",c);
}else{
b=b*3;
printf("Output is %d",b);
}
break;
case 4:
int b,c,d;
printf("enter 1st numaber");
scanf("%d",&b);
printf("enter 2nd numaber");
scanf("%d",&c);
printf("enter 3rd numaber");
scanf("%d",&d);
if(b==c||c==d||d==a)
{
printf("Two Output iS Equal");
}
else{
printf("There are no Output Is Equal");
}
break;
defualt:
printf("You Have Selected Wrong Option Try Again");
break;
}
getch();
}
Q4.Write a program which reads characters from a string and calculates the number of
vowels in it. It should print the string and the number of vowels in it.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char sen[150];
int i,vowels=0;
clrscr();
printf("Enter A Line Of String");
scanf("%[^\n]",sen);
for(i=0;sen[i]!='\0';++i)
{
if(sen[i]=='a'|| sen[i]=='e' || sen[i]=='i' ||
sen[i]=='o' || sen[i]=='u' || sen[i]=='A' ||
sen[i]=='E' || sen[i]=='I' || sen[i]=='O' ||
sen[i]=='U')
{
++vowels;
printf("Vowels in String is:-%c",sen[i]);
}
}
printf("number of vowels are=%d",vowels);
getch();
}
a) Request the user for two integers and outputs them and their sum.
b) Request the user for two integers and outputs their remainder after division.
c) Request the user for two floats and outputs their product.
d) Request the user for a word and prints it twice on the same row.
Write a C (main) program to provide the above functions as options to the user using
switch statement and performs the functions accordingly.
Ans:-
#include <stdio.h> //header file it take standered input out
#include<string.h> //header file it allow string data.
#include<conio.h> //header file it take console input out
void main()//main Function
{ //program Open
int a,b,c,d; string s; //declare variable
clrscr(); //clean the console Window
printf("Select A Option To Process\n1. Sum to digit.\n2. Show Reminder of two digit.\n3. show Product of Two Value.\n4. To Twice A Word."); //print the message
scanf("%d",&d); //take input
switch(d){ //check condition
case 1:
printf("Enter Value For A");
scanf("%d",&a);
printf("Enter Value For B");
scanf("%d",&b);
c=a+b; //here a and b is sum and store in c
printf("Sum Of A And B Is %d",c); //here it print output
break; //terminate The process
case 2:
printf("Enter Value For A");
scanf("%d",&a);
printf("Enter Value For B");
scanf("%d",&b);
c=a%b;
printf("Remaider Of A And B Is %d",c);
break;
case 3:
printf("Enter Value For A");
scanf("%d",&a);
printf("Enter Value For B");
scanf("%d",&b);
c=a*b;
printf("Sum Of A And B Is %d",c);
break;
case 4:
printf("Enter A Word");
scanf(“%s”,s);
int length =strlen(s);
for(int i=0;i<length;i++){
printf(“%s %s”,s[i],s[i]);
}
break;
default: //it show at the Time of wrong option selection
printf("You Have select A Wrong Option Please Try Again");
break;
}
getch();
}
Q2.Write an algorithm, draw a corresponding flowchart and write an interactive program to
convert a binary number to its decimal equivalent.
Ans program:
#include<stdio.h>
#include<conio.h>
void main(){
int num,temp,base=1,dec=0;
print("Enter Binary Number");
scanf("%d",&num);
temp=num;
while(temp>0){
int last_digit=temp%10;
temp=temp/10;
dec+=last_digit*base;
base=base*2;
}
printf("\nDecimal number is %d",dec);
getch();
}
Algorithm:
Pseudo code
step1: Start Program
step2: Input Num
step3: Initialize dec to o and temp equal num,base to one.
step4: while num greater zero
Step5: Initialize last_digit equal remainder temp
step6: Initialize tamp equal temp divide by 10.
Step7: Initializedec Plus equal last_digit multiply by base
step8: now base equal to base multiply by 2
step9: print the dec
step10: Close The Program
Q3. Write the following functions that:
a) Request the user to input a 5 digit number and reverse the given number and print it.
b) Request the user to input two floats and outputs the largest of the inputs.
c) Request the user to input an integer and, if the number is divisible by two, divides it by
two, otherwise multiplies it by three and output the result.
d) Request the user for three integers and output whether any of them are equal. Use only
one if-else-statement
Write a C (main) program to provide the above functions as options to the user using
switch statement and perform the functions accordingly.
Ans:-
#include<stdio.h>//header file allow standered input output
#include<conio.h>//header show console i/o
void main() //main function
{//start program
int a;//declare integer
printf("Please Select An Option To Perform Task\n1.Reverse The Number\2.Check Float Numaber largest\n3.check no is divisible by two otherwise multiplies by three\n4. check whether any of them are equal or not");//print message
scanf("%d",&a);//take input
switch(a)//check condition
{
case 1:
int b,rev=0,rem;
printf("enter 5 digit number");
scanf("%d",&b);
while(b>0)
{
rem=b%10;
rev=rev*10+rem;
b=b/10;
}
printf("reversed number:%d",rev);
break;
case 2:
float b,c;
printf("enter 1st float value");
scanf("%f",&b);
printf("enter 2nd float value");
scanf("%f",&c);
if(b>c)
{
printf("%f is Largest",b);
}
else if(b<c){
printf("%f is largest",c);
}else{
printf("Both Are Equal");
}
break;
case 3:
int b;
float c;
printf("enter A number");
scanf("%d",&b);
if(b%2==0){
c=b/2;
printf("output is %d",c);
}else{
b=b*3;
printf("Output is %d",b);
}
break;
case 4:
int b,c,d;
printf("enter 1st numaber");
scanf("%d",&b);
printf("enter 2nd numaber");
scanf("%d",&c);
printf("enter 3rd numaber");
scanf("%d",&d);
if(b==c||c==d||d==a)
{
printf("Two Output iS Equal");
}
else{
printf("There are no Output Is Equal");
}
break;
defualt:
printf("You Have Selected Wrong Option Try Again");
break;
}
getch();
}
Q4.Write a program which reads characters from a string and calculates the number of
vowels in it. It should print the string and the number of vowels in it.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char sen[150];
int i,vowels=0;
clrscr();
printf("Enter A Line Of String");
scanf("%[^\n]",sen);
for(i=0;sen[i]!='\0';++i)
{
if(sen[i]=='a'|| sen[i]=='e' || sen[i]=='i' ||
sen[i]=='o' || sen[i]=='u' || sen[i]=='A' ||
sen[i]=='E' || sen[i]=='I' || sen[i]=='O' ||
sen[i]=='U')
{
++vowels;
printf("Vowels in String is:-%c",sen[i]);
}
}
printf("number of vowels are=%d",vowels);
getch();
}

Comments
Post a Comment