Assignment Input Output

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

Basic input output Assignment 1

Name : Dhruva Kumar Mishra Enrollment No. : 0103EX181026

1. Write a C program to convert a given integer (in seconds) to hours, minutes and
seconds. 

Test Data :
Input seconds: 25300
Expected Output:
There are:
H:M:S - 7:1:40

Ans #include<stdio.h>

int main()

int hours,minutes,seconds,rs;

printf("\n enter seconds:");

scanf("%d",&seconds);

hours=seconds/3600;

minutes=(seconds-(3600*hours))/60;

rs=(seconds-(3600*hours+60*minutes));

printf("\nhours:minutes:seconds-%d:%d:%d",hours,minutes,rs);

return 0;

Ram Lovewanshi Mobile 7648904739 Page 1


Basic input output Assignment 1

2. Write a C program to convert a given integer (in days) to years, months and days,
assumes that all months have 30 days and all years have 365 days.  Test Data :
Input no. of days: 2535
Expected Output:
6 Year(s)
11 Month(s)
15 Day(s)

Ans #include<stdio.h>

void main()

int years,months,days,rds;

printf("\nenter days:");

scanf("%d",&days);

years=days/365;

months=(days-(365*years))/30;

rds=(days-(365*years+30*months));

printf("\nyears:months:days-%d:%d:%d",years,months,rds);

3. Write a C program that read 5 numbers and sum of all odd values between them. 

Test Data :

Ram Lovewanshi Mobile 7648904739 Page 2


Basic input output Assignment 1

Input the first number: 11


Input the second number: 17
Input the third number: 13
Input the fourth number: 12
Input the fifth number: 5
Expected Output:
Sum of all odd values: 46

Ans #include<stdio.h>

main()

int a,b,c,d,e,total;

printf("\nenter first no.");

scanf("%d",&a);

printf("\nenter second no.");

scanf("%d",&b);

printf("\nenter third no.");

scanf("%d",&c);

printf("\nenter fourth no.");

scanf("%d",&d);

printf("\nenter fifth no.");

Ram Lovewanshi Mobile 7648904739 Page 3


Basic input output Assignment 1

scanf("%d",&e);

if(a%2==0)

a=0;

if(b%2==0)

b=0;

if(c%2==0)

c=0;

if(d%2==0)

d=0;

if(e%2==0)

e=0;

total=a+b+c+d+e;

printf("\ntotal of all odd no.s is:%d",total);

Ram Lovewanshi Mobile 7648904739 Page 4


Basic input output Assignment 1

Q4.  Write a C program that reads two integers and checks whether they are multiplied

or not. 

Test Data :
Input the first number: 5
Input the second number: 15
Expected Output:
Multiplied!

#include<stdio.h>

void main()

int x,y;

printf("\nenter first no.");

scanf("%d",&x);

printf("\nenter second no.");

Ram Lovewanshi Mobile 7648904739 Page 5


Basic input output Assignment 1

scanf("%d",&y);

if(x>y)

if(x%y==0)

printf("\nmultilpied");

else

printf("\nnot multiplied");

else

if(y%x==0)

printf("\nmultiplied");

else

printf("\nnot multiplied");

5. Write a C program that reads an integer between 1 and 12 and print the month of the
year in English. 

Test Data :
Input a number between 1 to 12 to get the month name: 8
Expected Output:
August

Ram Lovewanshi Mobile 7648904739 Page 6


Basic input output Assignment 1

Ans #include<stdio.h>

void main()

int a;

printf("enter no.s from 1 to 12 to get the month name:");

scanf("%d",&a);

if(a==1)

printf("\njanuary");

else if(a==2)

printf("\nfebruary");

else if(a==3)

printf("\nMarch");

else if(a==4)

printf("\nApril");

else if(a==5)

printf("\nMay");

else if(a==6)

printf("\nJune");

else if(a==7)

printf("\nJuly");

Ram Lovewanshi Mobile 7648904739 Page 7


Basic input output Assignment 1

else if(a==8)

printf("\nAugust");

else if(a==9)

printf("\nSeptember");

else if(a==10)

printf("\nOctober");

else if(a==11)

printf("\nNovember");

else if(a==12)

printf("\nDecember");

else

printf("sorry a year contains only 12 months:");

6. Write a C program that read 5 numbers and counts the number of positive numbers

and negative numbers.  Test Data :


Input the first number: 5
Input the second number: -4
Input the third number: 10
Input the fourth number: 15
Input the fifth number: -1
Expected Output:

Ram Lovewanshi Mobile 7648904739 Page 8


Basic input output Assignment 1

Number of positive numbers: 3


Number of negative numbers: 2

Ans #include<stdio.h>

void main()

int a,b,c,d,e,pcount=0,ncount=0;

printf("enter first no.");

scanf("%d",&a);

printf("enter second no.");

scanf("%d",&b);

printf("enter third no.");

scanf("%d",&c);

printf("enter fourth no.");

scanf("%d",&d);

printf("enter fifth no.");

scanf("%d",&e);

if(a>0)

pcount++;

Ram Lovewanshi Mobile 7648904739 Page 9


Basic input output Assignment 1

else ncount++;

if(b>0)

pcount++;

else ncount++;

if(c>0)

pcount++;

else ncount++;

if(d>0)

pcount++;

else ncount++;

if(e>0)

pcount++;

else ncount++;

printf("\ntotal positvie no.s :%d",pcount);

Ram Lovewanshi Mobile 7648904739 Page 10


Basic input output Assignment 1

printf("\ntotal negative no.s:%d",ncount);

7. Write a C program that read 5 numbers and counts the number of positive numbers

and print the average of all positive values. 


Test Data :
Input the first number: 5
Input the second number: 8
Input the third number: 10
Input the fourth number: -5
Input the fifth number: 25
Expected Output:
Number of positive numbers: 4
Average value of the said positive numbers: 12.00

void main()

Ram Lovewanshi Mobile 7648904739 Page 11


Basic input output Assignment 1

int a,b,c,d,e,pcount=0,sum=0;

float avg;

printf("\nenter first no.:");

scanf("%d",&a);

printf("\nenter second no.:");

scanf("%d",&b);

printf("\nenter third no.:");

scanf("%d",&c);

printf("\nenter fourth no.:");

scanf("%d",&d);

printf("\nenter fifth no.:");

scanf("%d",&e);

if(a>0){

pcount++;

sum+=a;

if(b>0)

pcount++;

sum+=b;

Ram Lovewanshi Mobile 7648904739 Page 12


Basic input output Assignment 1

if(c>0)

pcount++;

sum+=c;

if(d>0)

pcount++;

sum+=d;

if(e>0)

pcount++;

sum+=e;

printf("\ntotal positive no.:%d",pcount);

printf("\nsum of all positive no.s:%d",sum);

avg=sum/pcount;

printf("\naverage of positive no.s:%f",avg);

Ram Lovewanshi Mobile 7648904739 Page 13


Basic input output Assignment 1

8. Write a C program that read 5 numbers and sum of all odd values between

them. 
Test Data :
Input the first number: 5
Input the second number: 7
Input the third number: 9
Input the fourth number: 10
Input the fifth number: 13
Expected Output:
Sum of all odd values: 34

#include<stdio.h>

void main()

int a,b,c,d,e,sum;

printf("\nenter first no.:");

scanf("%d",&a);

printf("\nenter second no.:");

scanf("%d",&b);

printf("\nenter third no.:");

scanf("%d",&c);

printf("\nenter fourth no.:");

scanf("%d",&d);

printf("\nenter fifth no.:");

Ram Lovewanshi Mobile 7648904739 Page 14


Basic input output Assignment 1

scanf("%d",&e);

if(a%2==0)

a=0;

if(b%2==0)

b=0;

if(c%2==0)

c=0;

if(d%2==0)

d=0;

if(e%2==0)

e=0;

sum=a+b+c+d+e;

printf("\nsum of all odd values:%d",sum);

9. Write a program that converts Centigrade to Fahrenheit. Expected Output :


Input a temperature (in Centigrade): 45
113.000000 degrees Fahrenheit.

Ram Lovewanshi Mobile 7648904739 Page 15


Basic input output Assignment 1

#include<stdio.h>

void main()

int c;

float f;

printf("\nenter temp. in celcius:");

scanf("%d",&c);

f=((c*9)/5+32);

printf("\ntemp. in fahrenheit:%f",f);

10. Write a C program that converts kilometres per hour to miles per hour

Expected Output :

Ram Lovewanshi Mobile 7648904739 Page 16


Basic input output Assignment 1

Input kilometres per hour: 15


9.320568 miles per hour

#include<stdio.h>

void main()

int km;

float miles;

printf("\nenter km:");

scanf("%d",&km);

miles=0.621*km;

printf("\nmiles:%f",miles);

11. Write a C program to check two given integers, and return true if one of

them is 30 or if their sum is 30.

Ram Lovewanshi Mobile 7648904739 Page 17


Basic input output Assignment 1

#include<stdio.h>

void main()

int a,b;

printf("\nenter first no.:");

scanf("%d",&a);

printf("\nenter second no.:");

scanf("%d",&b);

if(a==30||b==30||a+b==30)

printf("\ntrue");

else printf("false");

Ram Lovewanshi Mobile 7648904739 Page 18


Basic input output Assignment 1

12. Write a C program that takes hours and minutes as input, and calculates the total
number of minutes.

#include<stdio.h>

void main()

int hours,minutes;

printf("\nenter hours:");

scanf("%d",&hours);

printf("\nenter minutes:");

scanf("%d",&minutes);

(minutes=(60*hours)+(1*minutes));

printf("\ntotal minutes:%d",minutes);

13. Write a C program to integral quotient and remainder of a division

Test Data and Expected Output :

Input numerator : 2500


Input denominator : 235
quotient = 10, remainder = 150

Ram Lovewanshi Mobile 7648904739 Page 19


Basic input output Assignment 1

#include<stdio.h>
void main()
{
int num,denom,quo,rem;
printf("\nenter numerator:");
scanf("%d",&num);
printf("\nenter denominator:");
scanf("%d",&denom);
quo=num/denom;
rem=num%235;
printf("\nquotient=%d",quo);
printf("\nremainder=%d",rem);

14. Write a C program to compute the sum of the two given integers. If the sum is in
the range 10..20 inclusive return 30.

#include<stdio.h>

void main()

int a,b,sum;

printf("\nenter first no.:");

Ram Lovewanshi Mobile 7648904739 Page 20


Basic input output Assignment 1

scanf("%d",&a);

printf("\nenter second no.:");

scanf("%d",&b);

sum=a+b;

if(sum>=10&&sum<=20)

printf("\n30");

else

printf("\nsum:%d",sum);

15. Write a C program that accept two integers and return true if either one is
5 or their sum or difference is 5.

#include<stdio.h>

void main()

Ram Lovewanshi Mobile 7648904739 Page 21


Basic input output Assignment 1

int a,b,sum,diff;

printf("\nenter first no.:");

scanf("%d",&a);

printf("\nenter second no.:");

scanf("%d",&b);

sum=a+b;

diff=a-b;

if(a==5||b==5||sum==5||diff==5)

printf("\ntrue");

else

printf("\nfalse");

16. Write a C program to check whether two or more non-negative given integers have

the same rightmost digit.

#include<stdio.h>

void main()

Ram Lovewanshi Mobile 7648904739 Page 22


Basic input output Assignment 1

int a,b,c;

printf("\nenter first no:");

scanf("%d",&a);

printf("\nenter second no:");

scanf("%d",&b);

printf("\nenter third no:");

scanf("%d",&c);

a=a%10;

b=b%10;

c=c%10;

if(a==b==c)

printf("\ntrue");

else

printf("\nfalse");

17. Write a C program to find the larger from two given integers. However if the two

integers have the same remainder when divided by 5, then the return the
smaller integer. If the two integers are the same, return 0.

Ram Lovewanshi Mobile 7648904739 Page 23


Basic input output Assignment 1

#include<stdio.h>

int main(void){

printf("%d",test(11, 21));

printf("\n%d",test(10, 20));

printf("\n%d",test(10, 10));

int test(int x, int y)

if (x == y)

return 0;

else if ((x % 5 == y % 5)) /*&& x < y) || x > y)*/

Ram Lovewanshi Mobile 7648904739 Page 24


Basic input output Assignment 1

return ((x<y)?x:y);

else

return y;

18. Write a C program to check whether it is possible to add two integers to get the

third integer from three given integers.

#include<stdio.h>

void main()

int a,b,c;

printf("\nenter first no:");

scanf("%d",&a);

Ram Lovewanshi Mobile 7648904739 Page 25


Basic input output Assignment 1

printf("\nenter second no:");

scanf("%d",&b);

printf("\nenter third no:");

scanf("%d",&c);

if(c==a+b)

printf("\ntrue");

else printf("\nfalse");

19. Write a C program to check whether y is greater than x, and z is greater


than y from three given integers x,y,z.

Ram Lovewanshi Mobile 7648904739 Page 26


Basic input output Assignment 1

#include<stdio.h>

void main()

int a,b,c;

printf("\nenter first no:");

scanf("%d",&a);

printf("\nenter second no:");

scanf("%d",&b);

printf("\nenter third no:");

scanf("%d",&c);

if(b>a&&c>b)

printf("\nyes");

else

printf("\nno");

20. Write a C program to check two given integers, each in the range 10..99. Return
true if a digit appears in both numbers, such as the 3 in 13 and 33. 

Expected Output:

1
0
1

Ram Lovewanshi Mobile 7648904739 Page 27


Basic input output Assignment 1

#include<stdio.h>

void main()

int a,b,c;

printf("\nenter first no:");

scanf("%d",&a);

printf("\nenter second no:");

scanf("%d",&b);

if(a>10&&b>10&&a<99&&b<99)

if(a%10==b%10)

printf("\nyes");

else printf("\nno");

Ram Lovewanshi Mobile 7648904739 Page 28


Basic input output Assignment 1

Ram Lovewanshi Mobile 7648904739 Page 29

You might also like