Sunday, May 8, 2022

Simple Write a program assignment in C language-04

Learning C programming language is mandatory for today’s students [as one programming language], during their academic career. The C language has many mechanisms to deal with decision making, repetitive tasks, such as if, if…else, for, while etc. Here are some of such C codes which may asked in theory/practical exams.

C is a typed language, so no need of code explanation as everything will be cleared by itself by reading the code. If you know C, you know this code. It’s that simple!

The Code::Blocks IDE 20.03+MinGW and Cygwin tool are used to test the code.

Code7

Write A Program to display counting from 10 to 1 using for loop

 

 

 

//WAP#7:WAP to display counting from

//10 to 1 using for loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    for(int i=10; i >=1; i--)

        printf("%d\n",i);

 

    return 0;

}

//end of program

 

//-----------------------

//output WAP#7:

 

/*

10

9

8

7

6

5

4

3

2

1

*/

 

 

 

 

 

Code8

Write A Program to display even numbers between 1 and 20 using for loop

 

 

 

//WAP#8:WAP to display even numbers

//between 1 & 20 using for loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    for(int i=2; i <=20; i+=2)

        printf("%d\n",i);

 

    return 0;

}

//end of program

 

//--------------------------

//output WAP#8:

 

/*

2

4

6

8

10

12

14

16

18

20

*/

 

 

 

 

 

Code9

Write A Program to display a table for equivalent temperature in Fahrenheit to Celsius from 50F to 100F with an increment of 5

 

 

 

 

//WAP#9:WAP to display a table of

//equivalent temperature in Fahrenheit

//to Celsius from 50F to 100F with an

//increment of 5

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int fah; float Cel;

    //declare variables

    printf("Faharenheit\t Celisus\n");

    for( fah=50; fah <=100; fah=fah+5)

        {

            Cel=5.0/9.0*(fah-32);

            printf("%3d\t\t%6.2f\n",fah,Cel);

        }

 

 

    return 0;

}

//end of program

 

//-----------------------

//output WAP#9:

 

/*

Faharenheit      Celisus

 50              10.00

 55              12.78

 60              15.56

 65              18.33

 70              21.11

 75              23.89

 80              26.67

 85              29.44

 90              32.22

 95              35.00

100              37.78

*/

 

 

 

 

 

Code10

Write A Program to display user-defined series using while loop

 

 

 

//WAP#10:WAP to display user-defined

//series using while loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int i, j;//declare variables

    i = 0; j = 1;

 

    while(i <=6)

      {

         printf("%d\t%d\n",i,j);

         i=i+1; j=j*2;

      }

 

    return 0;

}

//end of program

 

//----------------------------

//output WAP#10:

 

/*

0       1

1       2

2       4

3       8

4       16

5       32

6       64

*/

 

 

 

 

 

Code11

Write A Program to display triangle shape using nested for loop

 

 

 

//WAP#11:WAP to display triangle

//shape using nested for loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    for(int i=1; i<=5; i++)

    {

        for(int j=1; j<=i; j++)

        {

            printf("*");

        }

        printf("\n");

    }

 

    return 0;

}

//end of program

 

//-------------------------

//output WAP#11:

 

/*

 

*

**

***

****

*****

 

*/

 

 

 

 

 

For such codes click CCode label or check next day post on right-side post history bar.

---till next post, take care and bye-bye.