Author: learnconline

Program in C to reverse a given Number 9

Program in C to reverse a given Number

Below is the C program to reverse a given number. This C program will accept a number (in a variable named “num”) and performs an operation to reverse the number. #include <stdio.h> #include <stdlib.h> int main(void) { int num=1234, newNum=0; while(num!=0){ newNum=newNum*10 + num%10; num=num/10; } printf(“\n”); printf(“%d”, newNum); return 1; } Output: 4321 Explanation: The statement while(num!=0) will be executed till value of num !=0 num%10 (read as num mod 10) will return the last digit. So in 1st iteration, it will return 4. So, newNum will become–> 0*10 + 4 –>4 Next line i.e. num/10 will return 123...

C data types 28

Data Types in C

The above video is an extract from the online course – “C Programming: The ultimate guide for beginners” which we are currently working on. Consider subscribing to Youtube channel – Aptuts in order to get latest updates on new videos and online C programming course. Data types in C determine the following:• Range of the data• Type of the data stored• Number of bytes it occupies in memory C supports following data types:• int – occupies 4 bytes of memory in 32-bit compiler• float – occupies 4 byes of memory• double – occupies 8 bytes of memory• char – occupies...

Search first occurrence of element in an array 9

Search first occurrence of element in an array

Write a program in C language that will accepts n of integer values from the user, accepts the integer element to be searched and displays the position of the element in the array. #include #include #include void main() { int arr[100],i,element,no; clrscr(); printf(“\nEnter the no of Elements: “); scanf(“%d”, &no); for(i=0;i

Addition of array elements in C 5

Addition of Array elements

Write a program in C that accepts number of array elements from the user, accepts array element values and calculates the sum/addition of all the array elements. The program should display the value of addition. #include<stdio.h> int main() { int arr[100], i, no,sum=0; clrscr(); printf(“\nEnter the no. of elements: “); scanf(“%d”,&no); for(i=0;i<no;i++) { printf(“\nEnter element %d”,i+1); scanf(“%d”, &arr[i]); } for(i=0;i<no;i++) { sum=sum+arr[i]; } printf(“\nsum of array element: %d”,sum); return 0; } Output: Enter the no. of elements: 5 Enter element 1 : 1 Enter element 2 : 2 Enter element 3 : 3 Enter element 4 : 4 Enter element...

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet