Assignment Input Output
Assignment Input Output
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;
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;
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 :
Ans #include<stdio.h>
main()
int a,b,c,d,e,total;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
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;
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;
scanf("%d",&x);
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
Ans #include<stdio.h>
void main()
int a;
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");
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
6. Write a C program that read 5 numbers and counts the number of positive numbers
Ans #include<stdio.h>
void main()
int a,b,c,d,e,pcount=0,ncount=0;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
scanf("%d",&e);
if(a>0)
pcount++;
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++;
7. Write a C program that read 5 numbers and counts the number of positive numbers
void main()
int a,b,c,d,e,pcount=0,sum=0;
float avg;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
scanf("%d",&e);
if(a>0){
pcount++;
sum+=a;
if(b>0)
pcount++;
sum+=b;
if(c>0)
pcount++;
sum+=c;
if(d>0)
pcount++;
sum+=d;
if(e>0)
pcount++;
sum+=e;
avg=sum/pcount;
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;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
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;
#include<stdio.h>
void main()
int c;
float f;
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 :
#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
#include<stdio.h>
void main()
int a,b;
scanf("%d",&a);
scanf("%d",&b);
if(a==30||b==30||a+b==30)
printf("\ntrue");
else printf("false");
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);
#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;
scanf("%d",&a);
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()
int a,b,sum,diff;
scanf("%d",&a);
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
#include<stdio.h>
void main()
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
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.
#include<stdio.h>
int main(void){
printf("%d",test(11, 21));
printf("\n%d",test(10, 20));
printf("\n%d",test(10, 10));
if (x == y)
return 0;
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
#include<stdio.h>
void main()
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(c==a+b)
printf("\ntrue");
else printf("\nfalse");
#include<stdio.h>
void main()
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
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
#include<stdio.h>
void main()
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
if(a>10&&b>10&&a<99&&b<99)
if(a%10==b%10)
printf("\nyes");
else printf("\nno");