#### Search results for void

##### Example:[1]
``````
Write a c program function to compute (a+b)^2 where the value of a and b will be provided by the user.
``````
``````
#include <stdio.h>
int get_squreof_no(int ,int );
void main()
{
int square,int1,int2;
printf("Enter the value of int1:");
scanf("%d",&int1);
printf("Enter the value of int2:");
scanf("%d",&int2);
square = get_squreof_no(int1,int2);
printf("The square result is:%d\n", square);
}
int get_squreof_no(int a, int b)
{
int r;
r = (a*a+b*b+2*a*b);
return r;
}

``````
##### Example:[2]
``````
Write a c program function to calculate the sum of two integers where the two integers will be provided by the user.
``````
``````
#include <stdio.h>
int Sum(int a,int b);
void main()
{
int int1,int2,sum;
printf("Enter first integer\n");
scanf("%d",&int1);
printf("Enter second integer\n");
scanf("%d",&int2);
sum = Sum(int1,int2);
printf("The sum is:%d\n",sum);
}
int Sum(int a,int b)
{
return a + b;
}
``````
##### Example:[3]
``````
Write a program for illustrating the use of inline function in c programming.
``````
``````
#include <stdio.h>
void inline test_inline_func1(int a, int b)
{
printf ("a=%d and b=%d\n", a, b);
}
int inline test_inline_func2(int x)
{
return x*x;
}
int main() {
int tmp;
test_inline_func1(2,4);
tmp = test_inline_func2(5);
printf("square val=%d\n", tmp);
return 0;
}
``````
##### Example:[4]
``````
Write a program to demonstrate the use of static keyword in C programming.
``````
``````
#include <stdio.h>
static int p;
int f(void) {
static int x = 0;
x++;
return x;
}
int y(void) {
int x = 0;
x++;
return x;
}
int main()
{
int j;
printf("Static variable x:%d\n", p);
for (j = 0; j < 5; j++) {
printf("Value of f(): %d\n", f());
}
for (j = 0; j < 5; j++) {
printf("Value of y(): %d\n", y());
}
return 0;
}
``````
##### Example:[5]
``````
Write a program with two files ext1.c and ext2.c to demonstrate the use of extern keyword
``````
``````
/* File ext1.c */
#include <stdio.h>
void call_fun();
int val2 = 90;
int main()
{
call_fun();
return 0;
}

/* File ext2.c */
#include <stdio.h>
extern int val2;
void call_fun()
{
printf("The value of val2 is %d\n",val2);
}
``````
##### Example:[6]
``````
Write a C program function to print a half pyramid using *
``````
``````
#include <stdio.h>
void printing();
int main()
{
printing();
return 0;
}
void printing()
{
int i,j;
for (i = 0;i <= 6; i++)
{
for (j = 1; j <= i; ++j)
{
printf("*");
}
printf("\n ");
}
}
``````
##### Example:[7]
``````
Write a c function to print asterisks on screen corresponding to each integer in an integer array.

``````
``````
#include <stdio.h>
int count[10] = {1, 3, 5, 2, 5, 3, 5, 6, 8, 10};
int main(void)
{
int i,j;
for (i = 0; i < sizeof(count) / sizeof(count[0]); i++)
{
for (j = 0; j < count[i]; j++)
{
printf("*");  /* Print asterisk              */
}
printf("\n"); /* Move to the next line       */
}
}

``````
##### Example:[8]
``````
Write a c program to add two 2-dimensional arrays or 2-D arrays.
``````
``````
#include <stdio.h>
int main( void ) {
int a[ 2 ][ 3 ] = { { 5, 6, 7 }, { 10, 20, 30 } };
int b[ 2 ][ 3 ] = { { 1, 2, 3 }, {  3,  2,  1 } };
int sum[ 2 ][ 3 ], row, column;

for( row = 0; row < 2; row++ )
for( column = 0; column < 3; column++ )
sum[ row ][ column ] =
a[ row ][ column ] + b[ row ][ column ];
/* Then print the results */
printf( "The sum is: \n\n" );
for( row = 0; row < 2; row++ ) {
for( column = 0; column < 3; column++ )
printf( "\t%d",  sum[ row ][ column ] );
printf("\n");   /* at end of each row */
}
return 0;
}

``````
##### Example:[9]
``````
Write a c program to calculate the first 20 Fibonacci numbers.
``````
``````
#include <stdio.h>
int main( void ) {
int i, fibonacci[ 20 ];
fibonacci[ 0 ] = 0;
fibonacci[ 1 ] = 1;
for( i = 2; i < 20; i++ )
fibonacci[ i ] = fibonacci[ i - 2 ] + fibonacci[ i - 1 ];
for( i = 0; i < 20; i++ )
printf( "Fibonacci[ %d ] = %f\n", i, fibonacci[ i ] );
}
``````
##### Example:[10]
``````
Write a C program function to reverse the string passed to it without using the c inbuilt library.
``````
``````
#include <stdio.h>
void RevString(char p[],char r[]);
void main()
{
char str[] = "Hello";
char res[10];
RevString(str,res);
printf("Reversed string is: %s\n",res);
}
void RevString(char d[],char s[])
{
int i,j,k,len = 0;
for(i = 0;d[i] != '\0';i++)
{
len++;
}
for(j = 0,k = len-1;d[j] != '\0';j++,k--)
{
s[j] = d[k];
}
s[len] = '\0';
}
``````
##### Example:[11]
``````
Write a c program function that reverses the string passed to it without declaring any new string within the function.
``````
``````
#include <stdio.h>
void reverse(char a[]);
int main() {
char str[10] = "Hello";
reverse(str);
printf("\nReverse string is :%s\n", str);
return (0);
}
void reverse(char d[])
{
int k,len = 0;
char temp;
int i = 0;
for(k = 0;d[k] != '\0';k++)
{
len++;
}
while(i < (len - 1))
{
temp = d[i];
d[i] = d[len-1];
d[len-1] = temp;
i++;
len--;
}
}
``````
##### Example:[12]
``````
Write a C program function to take a string as its input and return the first word of the string passed to it.

``````
``````
#include <stdio.h>
void getfword(char *s, char f_word[]);
int main() {
char str[] = "Hello how are you";
char res[20];
getfword(str,res);
printf("Result is:%s\n", res);
}
void getfword(char *s, char f_word[])
{
int i = 0;
while(s[i] != '\0')
{
if(s[i] == ' ')
{
break;
}else
{
f_word[i] = s[i];
f_word[i + 1] = '\0';
i++;
}
}
}

``````
##### Example:[13]
``````
Write a c program function to swap two integers using function pointers.
``````
``````
#include <stdio.h>
void (*fptr)(int * ,int * );
void function(int * ,int * );
int main()
{
int num1 = 20,num2 = 30;
printf("Before:%d,%d\n", num1,num2);
fptr = function;
(*fptr)(&num1,&num2);
printf("After:%d,%d\n", num1,num2);
return 0;
}
void function(int *a,int *b)
{
int copy;
copy = *a;
*a = *b;
*b = copy;
}
``````
##### Example:[14]
``````
Write a c program function to swap two integers using pointers.
``````
``````
#include <stdio.h>
void Swap(int *,int *);
void main()
{
int num1 = 10, num2 = 20, res;
printf("Before swap %d,%d,num2",num1,num2);
res = Swap(&num1,&num2);
printf("After swap %d,%d",num1,num2);
}
void Swap(int *a,int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

``````
##### Example:[15]
``````
Write a c program function to reverse the string passed to it using pointers and without using the c inbuilt library.
``````
``````
#include <stdio.h>
#include <stdlib.h>
void RevString(char *,char *);
int main()
{
char *str = "Hello";
char *res;
res = (char *)malloc(10);
RevString(str,res);
printf("Reversed string is %s\n",res);
return 0;
}
void RevString(char *s,char *r)
{
int i,j,k,len = 0;
for(i = 0;*(s+i) != '\0';i++)
{
len++;
}
for(j = 0,k = len-1;*(s+j) != '\0',k > -1;j++,k--)
{
*(r+j) = *(s+k);
}
}
``````
##### Example:[16]
``````
Write a c program function to return the same string after reversing it using pointers
``````
``````
#include <stdio.h>
#include <string.h>
void reverseString(char* str)
{
int l, i;
char *begin_ptr, *end_ptr, ch;
l = strlen(str);
begin_ptr = str;
end_ptr = str;
for (i = 0; i < l - 1; i++)
{
end_ptr++;
}
for (i = 0; i < l / 2; i++)
{
ch = *end_ptr;
*end_ptr = *begin_ptr;
*begin_ptr = ch;
begin_ptr++;
end_ptr--;
}
}
int main()
{
char str[10] = "Hello";
reverseString(str);
printf("Reverse of the string: %s\n", str);
return 0;
}

``````
##### Example:[17]
``````
Write a c program function to take your name as input using fgets stdin and print the name as output
``````
``````
#include <stdio.h>
#include <stdlib.h>
#define MAX_COUNT 20
void getName(char *name);
void main(){
char myName[20];
getName(myName);
}
void getName(char *name){
fgets(name,MAX_COUNT,stdin);
}
``````
##### Example:[18]
``````
Write a c program to accept a string as input and return the number of words present in it using pointers.

``````
``````
#include <stdio.h>
void NumOfWords(char *s, int *);
int main() {
char str[] = "Hello how are you";
int res = 1;
NumOfWords(str,&res);
printf("Result is:%d\n", res);
}
void NumOfWords(char *s, int *r)
{
int i = 0;
while(s[i] != '\0')
{
if(s[i] == ' ')
{
*r = *r + 1;
}
i++;
}
}

``````
##### Example:[19]
``````
Write a C program function to enter different book information(pages, author, search id) in a school library.
``````
``````
#include <stdio.h>
#define NO_BOOKS 3
struct Book
{
int pages;
char author[10];
int search_id;
};
void EnterBooks(struct Book *);
int main()
{
struct Book b[NO_BOOKS];
EnterBooks(b);
return 0;
}
void EnterBooks(struct Book *a)
{
int i;
for(i = 0;i < NO_BOOKS;i++)
{
printf("Enter %d book pages\n", i+1);
scanf("%d",&a->pages);
printf("Enter %d book author\n", i+1);
scanf("%s",&a->author);
printf("Enter %d search id\n", i+1);
scanf("%d",&a->search_id);
a++;
}
}
``````
##### Example:[20]
``````
Write a C program function to enter different book information(pages, author, search id) in a school library and display the existing books using structure pointers.

``````
``````
#include <stdio.h>
#include <stdlib.h>
#define NO_BOOKS 3
struct Book
{
int pages;
char author[10];
int search_id;
};
void EnterBooks(struct Book *);
void DisBooks(struct Book *);
int main()
{
struct Book *b;
b = (struct Book *)malloc(sizeof(struct Book)*NO_BOOKS);
if(b == NULL)
{
printf("Req memory allocation failed\n");
}else
{
EnterBooks(b);
DisBooks(b);
}
free(b);
return 0;
}
void EnterBooks(struct Book *a)
{
int i;
for(i = 0;i < NO_BOOKS;i++)
{
printf("Enter %d book pages\n", i+1);
scanf("%d",&a->pages);
printf("Enter %d book author\n", i+1);
scanf("%s",&a->author);
printf("Enter %d search id\n", i+1);
scanf("%d",&a->search_id);
a++;
}
}
void DisBooks(struct Book *a)
{
int i;
for(i = 0;i < NO_BOOKS;i++)
{
printf("Book %d pages %d\n",i+1,a->pages);
printf("Book %d author %s\n",i+1,a->author);
printf("Book %d book search id %d\n",i+1,a->search_id);
a++;
}
}

``````
##### Example:[21]
``````
Write a C program function to enter different book information(pages, author, search id) in a school library and display the existing books using structure arrays.

``````
``````
#include <stdio.h>
#define NO_BOOKS 3
struct Book
{
int pages;
char author[10];
int search_id;
};
void EnterBooks(struct Book *);
void DisplayBooks(struct Book *);
int main()
{
struct Book b[NO_BOOKS];
EnterBooks(b);
DisplayBooks(b);
return 0;
}
void EnterBooks(struct Book *a)
{
int i;
for(i = 0;i < NO_BOOKS;i++)
{
printf("Enter %d book pages\n", i+1);
scanf("%d",&a->pages);
printf("Enter %d book author\n", i+1);
scanf("%s",&a->author);
printf("Enter %d search id\n", i+1);
scanf("%d",&a->search_id);
a++;
}
}
void DisplayBooks(struct Book a[])
{
int i;
for(i = 0;i < NO_BOOKS;i++)
{
printf("Book %d pages %d\n",i+1,a[i].pages);
printf("Book %d author %s\n",i+1,a[i].author);
printf("Book %d book search id %d\n",i+1,a[i].search_id);
}
}
``````
##### Example:[22]
``````
Write a C program function to enter different book information(pages, author, search id) in a school library and search any book using search id and structure arrays.

``````
``````
#include <stdio.h>
#define NO_BOOKS 3
struct Book
{
int pages;
char author[10];
int search_id;
};
void EnterBooks(struct Book *);
struct Book *SrchBook(struct Book a[]);
int main()
{
struct Book b[NO_BOOKS];
EnterBooks(b);
struct Book *s;
s = SrchBook(b);
printf("Book pages:%d\n", s->pages);
printf("Book author:%s\n", s->author);
printf("Book search_id:%d\n", s->search_id);
return 0;
}
void EnterBooks(struct Book *a)
{
int i;
for(i = 0;i < NO_BOOKS;i++)
{
printf("Enter %d book pages\n", i+1);
scanf("%d",&a->pages);
printf("Enter %d book author\n", i+1);
scanf("%s",&a->author);
printf("Enter %d search id\n", i+1);
scanf("%d",&a->search_id);
a++;
}
}
struct Book *SrchBook(struct Book a[])
{
int i,id;
printf("Enter the book search id\n");
scanf("%d",&id);
for(i = 0;i < NO_BOOKS;i++)
{
if(id == a[i].search_id)
{
return &a[i];
}
}
if(i == NO_BOOKS)
{
printf("Invalid Search_id, try again\n");
return NULL;
}
}
``````
##### Example:[23]
``````
Write a C program function to enter different book information(pages, author, search id) in a school library and search any book using search id and structure pointers.
``````
``````
#include <stdio.h>
#include <stdlib.h>
#define NO_BOOKS 3
struct Book
{
int pages;
char author[10];
int search_id;
};
void EnterBooks(struct Book *);
struct Book *SrchBook(struct Book *);
int main()
{
struct Book *b;
b = (struct Book *)malloc(sizeof(struct Book)*NO_BOOKS);
if(b == NULL)
{
printf("Req memory allocation failed\n");
}else
{
EnterBooks(b);
struct Book *s;
s = SrchBook(b);
printf("Book pages:%d\n", s->pages);
printf("Book author:%s\n", s->author);
printf("Book search_id:%d\n", s->search_id);
}
free(b);
return 0;
}
void EnterBooks(struct Book *a)
{
int i;
for(i = 0;i < NO_BOOKS;i++)
{
printf("Enter %d book pages\n", i+1);
scanf("%d",&a->pages);
printf("Enter %d book author\n", i+1);
scanf("%s",&a->author);
printf("Enter %d search id\n", i+1);
scanf("%d",&a->search_id);
a++;
}
}
struct Book *SrchBook(struct Book *a)
{
int i,id;
printf("Enter the book search id\n");
scanf("%d",&id);
for(i = 0;i < NO_BOOKS;i++)
{
if(id == a->search_id)
{
return &a[i];
}
a++;
}
if(i == NO_BOOKS)
{
printf("Invalid Search_id, try again\n");
return NULL;
}
}
``````
##### Example:[24]
``````
Write a c program function to display all node data present in a singly linked list.
``````
``````
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node *next;
};
void Traverse();
void main()
{
Traverse();
}
{
struct Node *ptr;
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
ptr->data = val;
ptr->next = NULL;
}
}else
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
ptr->data = val;
}
}
}
void Traverse()
{
int n = 1;
while(ptr != NULL)
{
printf("Node %d data %d\n", n,ptr->data);
ptr = ptr->next;
n++;
}
}
``````
##### Example:[25]
``````
Write a c singly linked list program to add a node at the beginning of the list.
``````
``````
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node *next;
};
void main()
{
}
{
struct Node *ptr;
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
ptr->data = val;
ptr->next = NULL;
}
}else
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
ptr->data = val;
}
}
}
``````
##### Example:[26]
``````
Write a c program function to add new nodes at the end of a singly linked list.
``````
``````
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node *next;
};
void Traverse();
void main()
{
Traverse();
Traverse();
}
{
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
ptr->data = val;
ptr->next = NULL;
}
}else
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
while(aptr != NULL)
{
bptr = aptr;
aptr = aptr->next;
}
ptr->data = val;
bptr->next = ptr;
ptr->next = NULL;
}
}
}
void Traverse()
{
int n = 1;
while(ptr != NULL)
{
printf("Node %d data %d\n", n,ptr->data);
ptr = ptr->next;
n++;
}
}
``````
##### Example:[27]
``````
Write a c program function to add new nodes in the middle of a singly linked list.
``````
``````
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node *next;
};
void Traverse();
void main()
{
Traverse();
}
{
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
ptr->data = val;
ptr->next = NULL;
}
}else
{
ptr = (struct Node *)malloc(sizeof(struct Node ));
if(ptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
while(aptr != NULL)
{
bptr = aptr;
aptr = aptr->next;
}
ptr->data = val;
bptr->next = ptr;
ptr->next = NULL;
}
}
}
void Traverse()
{
int n = 1;
while(ptr != NULL)
{
printf("Node %d data %d\n", n,ptr->data);
ptr = ptr->next;
n++;
}
}
{
int count = 0;
{
printf("List is empty\n");
}else
{
while(aptr != NULL)
{
aptr = aptr->next;
count++;
}
printf("%d\n", count);
if(count < pos)
{
printf("We have less nodes than %d\n", pos);
}else
{
aptr = (struct Node *)malloc(sizeof(struct Node ));
if(aptr == NULL)
{
printf("Req memory allocation failed\n");
}else
{
count = 0;
while(count != pos)
{
cptr = bptr;
bptr = bptr->next;
count++;
}
aptr->data = val;
cptr->next = aptr;
aptr->next = bptr;
}
}
}
}
``````