Apply for Zend Framework Certification Training

c

< Operators in C Predict output on Increment and Decrement Operators in C >




1)Form a 4 digit number
Write a program that reads in 4 single digits and convert them into a single decimal integer.
Input
Input will contain 4 single digits separated by spaces. 
Output
For each input case, convert the single digits into a single decimal integer. 
Sample Input
2 7 5 9
Sample Output
2759
Solutions
#include <stdio.h>
/* Include other headers as needed */
int main(){
    int a,b,c,d,e;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    e = a*1000+b*100+c*10+d;
    printf("%d",e);
    return 0;
}

2) Reverse a 4 digit number
Write a program to reverse a 4 digit number.
Input
Each test case will contain a number n where 1000<=n<=9999.
Output
For each input case, calculate and print the reverse of the number.
Sample Input
1234
Sample Output
4321
solutions
#include <stdio.h>
/* Include other headers as needed */
int main(){
    int mynumber,reversenumber;
    scanf("%d",&mynumber);
    reversenumber =(mynumber%10*1000)+((mynumber/10)%10*100)+((mynumber/100)%10*10)+((mynumber/1000)%10*1);
    printf("%d\n",reversenumber);
    return 0;
}
3)Convert days into years, weeks and days
Write a C program to input number of days from user and convert it to years, weeks and days.
You can ignore the concept of leap year in this question.
Input Format
Each test case contains an integer denoting total number of days.
Output Format
Print the diameter years, weeks and days separated by space.
Sample Input
399
Sample Output
1 4 6
Solutions
#include <stdio.h>
int main(){
    int noofyears,days,remaningdays,remaningweeks,remaningday;
    scanf("%d",&days);
    noofyears =days/365;
    remaningdays= days%365;
    remaningweeks = remaningdays/7;
    remaningday = remaningdays-(remaningweeks*7);
    printf("%d %d %d",noofyears,remaningweeks,remaningday);
    return 0;
}
4) Given 2 angles of a triangle, find the 3rd angle
Write a C Program to input two angles from user and find third angle of the triangle.
Input Format
Each test case contains 2 integers denoting the 2 angles of triangle.
Output Format
Print the 3rd angle of triangle.
Sample Input
60 80
Sample Output
40
Solutions
#include <stdio.h>
int main(){
    int firstangle,secondangle,thirdangle;
    scanf("%d %d",&firstangle,&secondangle);
    thirdangle = 180-(firstangle+secondangle);
    printf("%d",thirdangle);
    return 0;
}

5) Sum of the first and the last digit of a 4 digit number
Write a program to find the sum of the first and last digit of a 4 digit number.
Input
Each test case will contain a number n where 1000<=n<=9999.
Output
For each input case, calculate and print sum of the first and last digit of the number
Sample Input
1234
Sample Output
5
Solutions
#include <stdio.h>
/* Include other headers as needed */
int main(){
    int fourdigitnumber,firstnumber,lastnumber,totalnumber;
    scanf("%d",&fourdigitnumber);
    firstnumber = fourdigitnumber/1000;
    lastnumber = fourdigitnumber%10;
    totalnumber = firstnumber+lastnumber;
    printf("%d",totalnumber);
    return 0;
}
6)Calculate amount using compound interest
Write a program to calculate the amount using compound interest .
Input Format
Each test case contains three floating numbers denoting principle amount, rate and time.
Output Format
Print the amount upto 1(one) decimal point as shown below.
Sample Input
1000 5 2
Sample output
1102.5
solution
#include <stdio.h>
#include <math.h>
int main(){
    float principalamount,rate,time,ci;
    scanf("%f %f %f",&principalamount,&rate,&time);
    ci= principalamount*pow((1+rate/100),time);
    printf("%.1f",ci);
    return 0;
}

< Operators in C Predict output on Increment and Decrement Operators in C >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top