C Language Programs | What Is Means of C Program

Q. What Is Means of Program?

Ans. Program is collection of instruction that performs a specific task when executed by a computer.

If you write a program in c language then you have knowledge about variable, data type, operator, that is basic knowledge of c language.You do not knowledge of variable, data type, operator ,then you are not write simple program in c language.

C Language Programs | What Is Means of C Program:

Q. Write a program sum of two variable?

Ans.  1. We include header file,these file is very important for a program.#include <stdio.h> and #include <conio.h>,these file containing many function.

2. Afterthat we declare three variable for sum of two variable.If you want read data from keyboard then you use scanf() and you want print value on the monitor then you use printf() function.Program of two variable sum in c language.

#include <stdio.h>
void main()
{

//  we declare three variable of integer type.
int a, b, sum;

// Enter the first value: This message show on your monitor.
printf(“Enter the first value:”);

// Read value for keyboard and this value is store in a variable.
scanf(“%d”, &a);

// Enter the second value: This message show on your monitor.
printf(“Enter the second value:”);

// Read value for keyboard and this value is store in b variable.

scanf(“%d”, &b);

// Assign a and b variable value in sum variable.
sum = a + b;
printf(“%d “, sum);

}

C Language Programs | What Is Means of C Program

Q. Write a C Language Programs of Negative and positive value?

Ans.

#include <stdio.h>
void main()
{

//  we declare no variable of integer type.
int no;

// Enter number: This message show on your monitor.
printf(“Enter number:”);

// Read value for keyboard and this value is store in no variable.
scanf(“%d”, &no);

 

if(no>=0)

{

printf(“This value is positive”);

}

else

{

printf(“This value is Negative”);

}
}

C Language Programs | What Is Means of C Program:

Q. Write C Language Programs of for loop?

Ans. We write a program print 2 number table in c language.

#include <stdio.h>
void main()
{

int no=2, i;

for(i=1; i<=10; i++)
{
printf(“%d\n”,n*i);
}

}

This program is print 2 table in c language.

 

Q. Write C Language Programs of for function?

A function is a group of statements that perform a task.We write a program of  function in c language.This program is print sum of two variable in the function.

#include <stdio.h>
int main()
{
int no1=0, no2=0;
printf(“enter number 1: “);
scanf(“%d”,&no1);
printf(“enter number 2: “);
scanf(“%d”,&no2);

int result = sum(no1, no2);
printf (“Output: %d”, result);

return 0;
}
int sum(int num1, int num2)
{
int sum=0;

sum = num1+num2;

return sum;
}

 

C Language Programs have two type function (1).Function overloading.(2) Function overriding.

(1)Function overloading means function have same name but argument list is different.

(2) Function overriding :function have same name and argument list is same is called function Function overriding.

C Language Programs | What Is Means of C Program:

Call by reference:The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. It means the changes made to the parameter affect the passed argument.

Call by Value: The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function.

C Language Programs | What Is Means of C Program:

Q. Writes a C Language Programs of array?

Ans. An array is collection of similar data type.

Write a program to find the average of n  numbers using arrays?

Ans.

#include <stdio.h>
void main()
{

// we declare no array of integer type.
int no[10], i=0, n=0, sum = 0, average=0;

//Enter a number for run loop.
printf(“Enter number: “);
scanf(“%d”, &n);
for(i=1; i<=n; ++i)
{
printf(“%d “,i+1);
scanf(“%d”, &marks[i]);
sum = sum +marks[i];
}
average = sum/n;

printf(“Average of marks  = %d”, average);

//getche() function is stop monitor screen.

getche();
}

 

Write a program of structure in c language.

Q. What is means of structure?

Structure is a composite data type declaration that defines a physically grouped list of variables to be placed under one name in a block of memory, allowing the different variables to be accessed.

We write a program of structure in c language?

#include <stdio.h>
#include <string.h>

struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};

void main( ) {

struct Books b1;
struct Books b2;

strcpy( b1.title, “C Programming”);
strcpy( b1.author, “Nuha Ali”);
strcpy( b1.subject, “C Tutorial”);
b1.book_id = 6495407;

/* strcpy() fuction is use for copy.This is inbuilt in string.h header file */

strcpy( b2.title, “Telecom Billing”);
strcpy( b2.author, “Zara Ali”);
strcpy( b2.subject, “Telecom Billing Tutorial”);
b2.book_id = 6495700;

/* print b1 info */
printf( “Book 1 title : %s\n”, b1.title);
printf( “Book 1 author : %s\n”, b1.author);
printf( “Book 1 subject : %s\n”, b1.subject);
printf( “Book 1 book_id : %d\n”, b1.book_id);

/* print Book2 info */
printf( “Book 2 title : %s\n”, b2.title);
printf( “Book 2 author : %s\n”, b2.author);
printf( “Book 2 subject : %s\n”, b2.subject);
printf( “Book 2 book_id : %d\n”, b2.book_id);

getche();
}

 

C Language Programs | What Is Means of C Program

Leave a Reply

Your email address will not be published. Required fields are marked *