C Programming - By examples

In this page you will get some basic C programming questions for practicing purpose and you will learn C programming by examples .

you can just copy paste the source from below and paste it to your compiler

Question -1   Write   program  to  input  an  uppercase  character  and  convert  it  into its equivalent lowercase character?



#include <stdio.h>
#include <string.h>
int main() 
{
   char s[100];
   int i;
   printf("\nEnter a string : ");
   gets(s);
   
   for (i = 0; s[i]!='\0'; i++) {
      if(s[i] >= 'a' && s[i] <= 'z') {
         s[i] = s[i] - 32;
      }
   }
   printf("\nString in Upper Case = %s", s);
   return 0;
}

Question-2 Write a program to input temperature in fahrenheit scale and display it in celsius scale ?





#include <stdio.h>
float temp_f;     /* degrees fahrenheit */
float temp_c;     /* degrees centigrade */
char line_text[50];        /* a line of input */

int main() {
 printf("Input a temperature (in Centigrade): ");
 fgets(line_text, sizeof(line_text), stdin);
 sscanf(line_text, "%f", &temp_c);

 temp_f = ((9.0 / 5.0) * temp_c) + 32.0;
 printf("%f degrees Fahrenheit.\n", temp_f);

 return(0);
}

Question -3 Write a program to swap two integer number without using variable ?



#include <stdio.h>
int main() 
{
    double a, b;
    printf("Enter a: ");
    scanf("%lf", &a);
    printf("Enter b: ");
    scanf("%lf", &b);
    // Swapping process
    a = a - b;
    b = a + b;
    a = b - a;
    printf("After swapping, a = %.2lf\n", a);
    printf("After swapping, b = %.2lf", b);
    return 0;
}

Question -4 Write a program to input five subject marks of a student and total , average and percentage of marks ?



#include <stdio.h>
/**
 * C program to calculate total, average and percentage of five subjects
 */

#include 

int main()
{
    float eng, phy, chem, math, comp; 
    float total, average, percentage;

    /* Input marks of all five subjects */
    printf("Enter marks of five subjects: \n");
    scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);

    /* Calculate total, average and percentage */
    total = eng + phy + chem + math + comp;
    average = total / 5.0;
    percentage = (total / 500.0) * 100;

    /* Print all results */
    printf("Total marks = %.2f\n", total);
    printf("Average marks = %.2f\n", average);
    printf("Percentage = %.2f", percentage);

    return 0;
}

Question-5 Write a program o input a character from a keyboard and check whether it is an  alphabet digit or special symbol ?



#include <stdio.h>
/**
 * C program to check alphabet, digit or special character
*/
int main()
{
    char ch;

    /* Input character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);


    /* Alphabet check */
    if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        printf("'%c' is alphabet.", ch);
    }
    else if(ch >= '0' && ch <= '9')
    {
        printf("'%c' is digit.", ch);
    }
    else 
    {
        printf("'%c' is special character.", ch);
    }

    return 0;
}

Question-6  Write  program  to  find  the  grade  of  an  emp  by  finding  gross  salary where basic salary given and ta=5%, da=7.5% and hra=10% of basic salary using ladder else if ?


Gross salary    grade 

>=1000         A

75000-99999    B

50000-74999    C
20000-49999    D
<20000 div="" nbsp="">




#include <stdio.h> 
int main()
{
float bs,ta,da,hra,gs; 
clrscr();
printf(“enter basic salary of an emp\n”); 
scanf(“%f”,&bs);
ta=0.05*bs;
 da=0.075*bs;
 hra=0.1*bs;
 gs=bs+ta+da+hra; 
if(gs>=100000)
printf(“a grade employee”);
else if(gs>=75000&&gs<100000 b="" else="" employee="" grade="" gs="" if="" printf="">=50000&&gs<75000 c="" else="" employee="" grade="" gs="" if="" printf="">=20000&&<50000 0="" code="" d="" e="" else="" employee="" grade="" printf="" return="">









C Programming - By examples C Programming - By examples Reviewed by Digital Roy on January 12, 2020 Rating: 5

No comments:

Powered by Blogger.