Thursday, May 5, 2022

Simple Write a program assignment in C language-01

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.

Code1a

Write A Program to display 1 to10 using while loop

 

 

 

//WAP#1a:WAP to display 1 to 10 using while loop

 

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int i; //declare index number

    i = 1; //initialize i to first value

 

    while (i <= 10)

    {

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

        i++;

    }

 

    return 0;

}

//end of program

 

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

//output WAP#1a:

 

/*

1

2

3

4

5

6

7

8

9

10

*/

 

 

 

 

 

Code1b

Write A Program to display 1 to10 using for loop

 

 

 

//WAP#1b:WAP to display 1 to 10 using for loop

 

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

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

    {

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

    }

 

    return 0;

}

//end of program

 

 

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

//output WAP#1b:

 

/*

1

2

3

4

5

6

7

8

9

10

*/

 

 

 

 

 

Code1c

Write A Program to ask base value from user, and then display 1 to base value using for loop

 

 

 

//WAP#1c:WAP to ask base value from user,

//& then display 1 to base value using for loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

   int num; //declare num variable

 

   printf("Enter base value [integer]: ");

   scanf("%d",&num); //get base value

 

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

    {

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

    }

 

    return 0;

}

//end of program

 

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

//output WAP#1c:

 

/*

Enter base value [integer]: 5

1

2

3

4

5

*/

 

 

 

 

 

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.

No comments:

Post a Comment