Pages

Saturday, December 31, 2022

C program to print Memory Address of a variable

In C program, we use variables to store some value. Value of any variables are stored in a memory.

We can print memory address using following two methods:
  • By using address of (&) operator
  • By using pointer variable
 "%p" is a format specifier to print a memory address in C language.

Let's see a program to print a memory address of a variable.


#include<stdio.h>

int main(){
	int number=5;
	float percen = 80.5;
	
	printf("Memory address of number variable: %p \n", &number);
	printf("Memory address of percen variable: %p", &percen);
	
	return 0;
}

Output of Program

Memory address of number variable: 000000051FE1C
Memory address of percen variable: 000000051FE18

Note:

You will get different memory address as output in your program execution.
At every run your output may change.





Tuesday, June 28, 2022

Palindrome numbers between give range

This program will print list of palindrome numbers between given range. 

// C Program to Generate palindrome numbers in a given range of numbers.
#include<stdio.h>

int main(){
   int i, start, end, rem, rev_num, temp;

   printf("Enter first number (lower limit): ");
   scanf("%d",&start);

   printf("Enter last number (upper limit): ");
   scanf("%d",&end);

   printf("List of Palindrome numbers between %d - %d: ",start, end);
   
   for(i=start; i<=end; i++)
   {
      temp = i;
      rev_num=0;
      
      while(temp){
         rem = temp%10;
         temp = temp/10;
         rev_num = rev_num*10 + rem;
      }
      if(i == rev_num)
         printf("%d ", i);
   }
   return 0;
}

Output of program
Enter first number (lower limit): 80
Enter last number (upper limit): 150
List of Palindrome numbers between 70 - 200: 88 99 101 111 121 131 141


Tuesday, May 31, 2022

Flowchart to print Series of Numbers divisible by 3

Draw a flowchart to print Series of Numbers divisible by 3:

2178  726  242  81  27  9  3  1 

Logic: 

  • Step 1: Read a starting number which is divisible by 3
  • Step 2: Divide current number by 3 to get a next number
  • Step 3: Repeat Step 2 until you get a number 1. 
Following flowchart is prepared using a Raptor Tool.

Flowchart to print series of numbers divisible by 3
Figure: Flowchart to print series of numbers divisible by 3


This Raptor flowchart also uses a CEILING function. In Raptor, CEILING returns the lowest integer value greater than or equal to the provided argument. 

For example, 

  • CEILING(15.8) is 16 
  • CEILING(3.2) is 4 
  • CEILING(- 4.2) is - 4

You may like to visit following top 10 flowcharts.





Saturday, April 9, 2022

C program to create an array of student names

This program is based on C programming String and an Array concept.


Problem definition: Write a C program to create an array of student names.

//C Program to create an array of student names

#include<stdio.h>

int main(){
	char name[5][20]; 
	//This can store 5 names; maximum 20 characters in each name
	
	int i;
	//Logic to Read name of 5 students
	for(i=0; i<5; i++){
		printf("Enter name %d:", i+1);
		gets(name[i]);
	}
	printf("List of student names stored: \n");
	//Logic to print name of 5 students
	for(i=0; i<5; i++){
		printf("%s \n", name[i]);
	}
	return 0;
}

Output of the program

Enter name 1:Amit
Enter name 2:Sunit
Enter name 3:Kamlesh
Enter name 4:Bhargav
Enter name 5:Alpesh

List of student names stored:
Amit
Sunit
Kamlesh
Bhargav
Alpesh

* * *





Sunday, January 23, 2022

Check whether a character is an alphabet, digit or special character

This program is based on C Programming Decision making concept (use of if..else statement).

Problem definition: Write a C program to check whether a given character is an alphabet, digit or special character.

#include <stdio.h>
int main()  
{  
    char chr;  

    printf("Enter a character: ");  
    scanf("%c", &chr);  
  
    /* logic to check whether it is an alphabet */  
    if((chr >= 'a' && chr<='z') || (chr>='A' && chr<='Z'))  
    {  
        printf("It is an alphabet.\n");
    }  
    else if(chr>='0' && chr<='9') /* to check digit */  
    {  
        printf("It is a digit.\n");  
    }  
    else /* else special character */
    {  
        printf("It is a special character.\n");  
    }  
}

Sample output 1

Enter a character: A
It is an alphabet.

Sample output 2

Enter a character: 5
It is a digit.

Sample output 3
Enter a character: @
It is a special character.