Program to Read a String From the User and Print It Using a Character Pointer
C++ program to accept assortment input and impress using For loop
In this article, nosotros will discuss the concept of C++ program to accept array input and print using For loop
In this postal service, we are going to larn how to write a programme to read array input and impress given elements of an assortment using for loop in C++ language
Code to read input and print of array elements
Code to have input and print integer of an array using for loop
In this code, we are going to learn how to read integer array input given by user and print the them using for loop in C++ linguistic communication
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int i,len; //integer variable announcement cout<<"Enter the Array length: "; //Ask input for array length cin>>len; //Reading the input for array length int num[len]; //Array declaration cout<<"\n";//move to next line cout<<"Enter the Number for assortment :"; //Ask input for elements(numbers) for(i=0; i<len; i++){//input using for loop cin>>num[i]; //Reading the assortment elements from user } cout<<"\ndisplay the number\northward"; for(i=0; i<len; i++){//display elements using for loop cout<<num[i]; cout<<("\n"); } getch(); return 0; } When the to a higher place code is executed, it produces the post-obit result
Programme 2
#include <iostream> #include <conio.h> using namespace std; int main() { int i,len;//integer variable declaration cout<<"Enter the Array length: "; //Ask input from the user for array length cin>>len; //Reading the input for array length int marks[len]; //Assortment announcement - integer cout<<"\northward";//move to next line //Ask input for elements(number) for(i=0; i<len; i++){//input using for loop cout<<"Enter the marks "<<"marks["<<i<<"] :"; cin>>marks[i]; //Reading the array elements from user } cout<<"\ndisplay the marks\due north"; for(i=0; i<len; i++){//display elements using for loop cout<<"marks["<<i<<"] :"<<marks[i]; cout<<("\n"); } getch(); render 0; } When the above lawmaking is executed, it produces the following upshot
Enter the array length: 5 Enter the marks marks[0]: 46 Enter the marks marks[1]: 78 Enter the marks marks[2]: 94 Enter the marks marks[three]: 36 Enter the marks marks[4]: 50 Brandish the marks marks[0]=46 marks[1]: 78 marks[2]: 94 marks[three]: 36 marks[four]: 50
Code to accept input and print String of an assortment using for loop
In this lawmaking, we are going to learn how to read string array input given by user and print them using for loop in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { string str[20]; //Single D assortment declaration int len;//Declare variable for length cout<<"Enter array length\due north"; //Inquire input from the user for length cin>>len; //Reading the input for length cout<<"\nEnter students name\north"; //Ask enter the student proper noun for(int i=0; i<len; i++){ cin>>str[i]; }//Enter the students name using for loop cout<<"\nEntered students names are:\north"; for(int i=0; i<len; i++){ cout<<str[i]<<"\n"; //Display the students name } getch(); return 0; } When the above code is executed, information technology produces the following effect
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { string str[20]; //Unmarried D array declaration int len;//Declare variable for length cout<<"Enter assortment length\north"; //Enquire input from the user for length cin>>len; //Reading the input for length cout<<"\nEnter students name\north"; //Ask enter the student name for(int i=0; i<len; i++){ cout<<"Enter the string"<<" str=["<<i<<"]: "; cin>>str[i]; }//Enter the students name using for loop cout<<"\nEntered students names are:\north"; for(int i=0; i<len; i++){ cout<<"Your entered cord is:"<<" str=["<<i<<"]: "; cout<<str[i]<<"\n"; //Display the students proper name } getch(); return 0; } When the above code is executed, it produces the following result
Code to take input and print character of an array using for loop
In this code, nosotros are going to learn how to read character assortment input given by user and print the them using for loop in C++ language
Programme 1
#include <iostream> #include <conio.h> using namespace std; int main() { int i,len; //integer variable announcement cout<<"Enter the Array length: "; //request input for array length cin>>len; //Reading the input for array length char char_array[len]; //declare grapheme Array cout<<"\n"; //move to next line cout<<"Enter the characters for array :"; //Request input for elements(numbers) for(i=0; i<len; i++){//input using for loop cin>>char_array[i]; //Reading the array elements from user } cout<<"\ndisplay the characters\n"; for(i=0; i<len; i++){//print elements using for loop cout<<char_array[i]; cout<<("\n"); } getch(); return 0; } When the above code is executed, it produces the following result
Enter the array length:x Enter the characters for array :Code4javac display the characters C o d e 4 j a v a c
Program 2
#include <iostream> #include <conio.h> using namespace std; int principal() { int i,len; //variable proclamation - integer cout<<"Enter the Array length: "; //request input for array length cin>>len; //Reading the input for array length char char_array[len]; //Array annunciation - char array cout<<"\n";//movement to adjacent line cout<<"Enter the characters for array :\due north"; //Ask input for elements(numbers) for(i=0; i<len; i++){//input using for loop cout<<"char_array["<<i<<"]:"; cin>>char_array[i]; //Reading the array elements from user } cout<<"\ndisplay the characters\n"; for(i=0; i<len; i++){//display elements using for loop cout<<"char_array["<<i<<"]:"<<char_array[i]; cout<<("\due north"); } getch(); return 0; } When the above code is executed, it produces the post-obit event
Suggested for you
For loop in C++ language
Operator in C++ language
Variable in C++ language
Data type in C++ language
One dimensional array in C++ language
Similar post
Java program to read and print array elements using for loop
Java plan to read and print array elements using while loop
Java plan to read and print array elements using Do-while loop
C code to read and print array elements using for loop
C code to read and impress assortment elements using while loop
C code to read and print array elements using do-while loop
C++ programme to read and print array elements using for loop
C++ program to read and print array elements using while loop
C++ program to read and print array elements using practise-while loop
Program to Read a String From the User and Print It Using a Character Pointer
Source: https://code4javac.com/2021/07/23/c-program-to-accept-array-input-and-print-using-for-loop/
0 Response to "Program to Read a String From the User and Print It Using a Character Pointer"
Post a Comment